File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
src/main/java/dev/openfga/sdk/errors Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1818import org .openapitools .jackson .nullable .JsonNullableModule ;
1919
2020public 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 *
You can’t perform that action at this time.
0 commit comments