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

custom mapper should not always return a 503 when the mapping fails #3610

Merged
merged 6 commits into from
Jan 27, 2024

Conversation

JeffreyThijs
Copy link
Contributor

fixes #3609

@JeffreyThijs JeffreyThijs requested a review from kaniyan as a code owner January 22, 2024 13:23
Comment on lines 286 to 302
private Throwable mapException(final AsyncResult<HttpResponse<Buffer>> httpResponseAsyncResult) {
final Optional<HttpResponse<Buffer>> httpResponse = Optional.ofNullable(httpResponseAsyncResult.result());
final int statusCode = httpResponse.map(HttpResponse::statusCode).orElse(HttpURLConnection.HTTP_INTERNAL_ERROR);
if (statusCode >= 400 && statusCode < 500) {
return new ClientErrorException(statusCode, httpResponseAsyncResult.cause());
}
return new ServerErrorException(statusCode, httpResponseAsyncResult.cause());
}

private Throwable mapException(final AsyncResult<HttpResponse<Buffer>> httpResponseAsyncResult, final String message) {
final Optional<HttpResponse<Buffer>> httpResponse = Optional.ofNullable(httpResponseAsyncResult.result());
final int statusCode = httpResponse.map(HttpResponse::statusCode).orElse(HttpURLConnection.HTTP_INTERNAL_ERROR);
if (statusCode >= 400 && statusCode < 500) {
return new ClientErrorException(statusCode, message);
}
return new ServerErrorException(statusCode, message);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we reduce the code duplication by e.g. having just one method which accepts an Optional<String> message?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might also want to consider using org.eclipse.hono.client.util.StatusCodeMapper.from() to create a context specific ServiceInvocationException ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, now it uses the StatusCodeMapper.

Copy link
Contributor

@sophokles73 sophokles73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for contributing 👍

@sophokles73 sophokles73 merged commit ddebeae into eclipse-hono:master Jan 27, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ccustom mapper should not always return a 503 when the mapping fails
2 participants