-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Reactive Rest Client should allow extracting response status from WebClientApplicationException #17397
Comments
@geoand: you appeared in the git blame ;) Thanks for your help! |
I'll have a look |
This is done by making the response code queryable Fixes: quarkusio#17397
First of all I opened #17402 to make the exception more usable. However, since the exception handling behavior of the client has changed significantly in It would look something like this: class WebClientApplicationExceptionMapper : ResponseExceptionMapper<WebClientApplicationException> {
override fun toThrowable(response: Response?) = WebClientApplicationException(response!!.statusInfo.statusCode, response!!.statusInfo.reasonPhrase)
} and you would add Then your server exception mapper (
|
Thanks @geoand for the super fast response and PR! Do I understand you correctly that in Quarkus 2.0, we will always have to implement our own Regarding the |
You don't to implement it. You only implement it if you want to convert a response code received from the client to a specific exception.
I can't comment on this as I don't know why |
This is done by making the response code queryable Fixes: quarkusio#17397
This is done by making the response code queryable Fixes: quarkusio#17397
If the interface method is declared to throw some exception, an exception mapper can return such an exception and it shouldn't be wrapped in anything IIRC. |
Make WebClientApplicationException usable from application code
Describe the bug
When the rest client makes a call to an external service, that call can fail with a non-OK status code (e.g. 401 when a token timed out). In such a case, the reactive rest client creates a
WebClientApplicationException
(seequarkus/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/handlers/ClientSetResponseEntityRestHandler.java
Line 24 in e21b6c2
Thus, the only way to find out the status code of the response of the call is to parse the message of the
WebClientApplicationException
. In my case I need the status because I implement a service similar to a "proxy" and therefore need to return the same status code from my service to my clients.Is there a reason not to use the standard
javax.ws.rs.WebApplicationException
? If I recall correctly, that was used by the standard rest client.Furthermore, there is a difference in the type of Exception you get depending on the return type of your rest client method. If you return a
Uni<MyDto>
and the call receives a non-OK status, you get aWebClientApplicationException
. However, if you return aUni<Response>
in the rest client method, you get aProcessingException
that contains a standardjavax.ws.rs.WebApplicationException
. See the reproducer for more details.Expected behavior
Uni<Dto>
orUni<Response>
.Actual behavior
WebClientApplicationException
only contains the status code in the message from which we would need to parse it.To Reproduce
2021-05-20-reactive-restclient-exceptions.zip.
./gradlew quarkusDev
Uni<Dto>
. You will receive the following error object:Uni<Response>
. You will now receive the following error object:Additional context
main
, theWebClientApplicationException
also only takes the message argument. So issue 1 persists. Issue 2 I haven't tested yet.The text was updated successfully, but these errors were encountered: