Skip to content

Commit cdb089c

Browse files
committed
fix: use unknown err code and msg raw resp
1 parent bef34e9 commit cdb089c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/main/java/dev/openfga/sdk/errors/FgaError.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.openapitools.jackson.nullable.JsonNullableModule;
1919

2020
public class FgaError extends ApiException {
21+
private static final String UNKNOWN_ERROR_CODE = "unknown_error";
22+
2123
private String method = null;
2224
private String requestUrl = null;
2325
private String clientId = null;
@@ -145,8 +147,9 @@ public static Optional<FgaError> getError(
145147
error.setApiErrorCode(resp.getCode());
146148
error.setApiErrorMessage(resp.getMessage());
147149
} catch (JsonProcessingException e) {
148-
// Fall back to using raw response body as error message if parsing fails
149-
error.setApiErrorMessage(body);
150+
// Wrap unparseable response
151+
error.setApiErrorCode(UNKNOWN_ERROR_CODE);
152+
error.setApiErrorMessage("Unable to parse error response. Raw response: " + body);
150153
}
151154
}
152155

@@ -297,6 +300,16 @@ public boolean isValidationError() {
297300
return "validation_error".equals(apiErrorCode);
298301
}
299302

303+
/**
304+
* Checks if this is an unknown error due to unparseable response.
305+
* This occurs when the error response could not be parsed as JSON.
306+
*
307+
* @return true if this is an unknown error
308+
*/
309+
public boolean isUnknownError() {
310+
return UNKNOWN_ERROR_CODE.equals(apiErrorCode);
311+
}
312+
300313
/**
301314
* Checks if this is a not found (404) error.
302315
*

0 commit comments

Comments
 (0)