Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Exception Handling for OpenFGA Client Errors (e.g., TupleAlreadyExistsException) #113

Open
ankit-sapkota opened this issue Sep 11, 2024 · 0 comments

Comments

@ankit-sapkota
Copy link

Overview

When working with the OpenFGA client, errors such as ExecutionException with FgaApiValidationError as the cause make it difficult to pinpoint specific issues. For example, writing a tuple that already exists throws a generic error, requiring manual parsing of the underlying message to identify the cause.

Problem

Currently, developers must manually parse the error message to determine the specific cause, like a duplicate tuple. This approach adds complexity and can lead to mistakes when handling multiple error types.

Proposed Solution

Introduce custom exceptions (e.g., TupleAlreadyExistsException, InvalidTupleFormatException) that allow developers to handle specific errors directly without parsing error messages.

Benefits

  • Simplifies error handling by catching specific exceptions.
  • Improves code readability and maintainability.
  • Reduces the risk of incorrect error handling due to manual parsing.

Current Workaround

FgaApiValidationError error = (FgaApiValidationError) e.getCause();
String responseData = error.getResponseData();

ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> responseMap = null;
try {
    responseMap = objectMapper.readValue(responseData, new TypeReference<>() {});
} catch (JsonProcessingException ex) {
    throw new CustomException("Failed to parse response from openfga");
}

String message = (String) responseMap.get("message");
if (message.startsWith("cannot write a tuple which already exists:")) return;

Improved Solution

With custom exceptions like TupleAlreadyExistsException, the error handling could be simplified:

try {
    // Write tuple
} catch (ExecutionException e) {
    TupleAlreadyExistsException cause =e.getCause();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant