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

fix: errorMapping in ResponseCodes with "4XX" and "5XX" Pattern #1735

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void handleFailedResponse(Response nativeResponse, HashMap<String, Parsa
int statusCode = nativeResponse.code();
String statusCodeString = String.valueOf(statusCode);
if (errorMappings == null ||
!errorMappings.containsKey(statusCodeString) ||
!errorMappings.containsKey(statusCodeString) &&
!(statusCode >= 400 && statusCode <= 499 && errorMappings.containsKey("4XX")) &&
!(statusCode >= 500 && statusCode <= 599 && errorMappings.containsKey("5XX"))) {
throw new ApiExceptionBuilder()
Expand All @@ -83,7 +83,15 @@ private void handleFailedResponse(Response nativeResponse, HashMap<String, Parsa
.withResponseHeaders(HeadersCompatibility.getResponseHeaders(nativeResponse.headers()))
.build();
} else {
Parsable result = parseNode.getObjectValue(errorMappings.get(statusCodeString));
String statusCodePattern = statusCodeString;
if (!errorMappings.containsKey(statusCodePattern)) {
if (statusCode >= 400 && statusCode <= 499 && errorMappings.containsKey("4XX")) {
statusCodePattern = "4XX";
} else if (statusCode >= 500 && statusCode <= 599 && errorMappings.containsKey("5XX")) {
statusCodePattern = "5XX";
}
}
Parsable result = parseNode.getObjectValue(errorMappings.get(statusCodePattern));
if (!(result instanceof Exception)) {
throw new ApiException("The server returned an unexpected status code and the error registered for this code failed to deserialize: " + statusCodeString);
}
Expand Down
Loading