Feature Request: Exception Handling for OpenFGA Client Errors (e.g., TupleAlreadyExistsException)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 54
- Forks
- 26
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 9
Description
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();
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the OpenFGA client’s tuple-writing path and its handling of ExecutionException and FgaApiValidationError; the issue provides no file or test names. Define the supported error cases and verify that duplicate and invalid tuples can be handled without parsing response messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, authorization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100