-
Notifications
You must be signed in to change notification settings - Fork 137
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
Conversation
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); | ||
} |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
...
There was a problem hiding this comment.
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
.
.../mqtt-base/src/test/java/org/eclipse/hono/adapter/mqtt/impl/HttpBasedMessageMappingTest.java
Show resolved
Hide resolved
There was a problem hiding this 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 👍
fixes #3609