-
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
Custom ExceptionMapper for WebApplicationException or subclasses doesn't work #15272
Comments
I think the faulty behavior between the client and the server has been fixed recently with a RESTEasy upgrade. @sberyozkin would know more. |
@Faboli7 Does the WAE you throw in point 2 of steps to reproduce contain response with entity/body? |
Most likely duplicate of #4031 |
Please see if my feedback on related issue applies to your case. Also to double check your case consider throwing |
Hi, However, I tried without a body and the
Using Quarkus 1.11.3 with following extensions:
Something interesting though, if I change the http method of ResourceB and serviceB to HEAD, then my mapper is called and changes the status from 500 to 400 as expected. So it seems that even with no entity, a Response to a GET is considered to have a body. I also tried with OPTIONS with the same result as the GET, and originally I had the issue with a POST. Something else, if I only change ResourceB to HEAD, but not ServiceB, to have the framework return a 405 error instead of my own code, the mapper is triggered too and changes the status from 405 to 400. I hope this can help understand the issue better. Anyway, the same day I created this issue, quarkus 1.12 was released and it seems like it could solve the issue, since :
I haven't tested this version yet (I'll do that next), but it could be that the mapper is triggered now. I'll keep you posted after I try with 1.12 but it's probably still interesting to understand where the issue comes from. |
@Faboli7 your reproducer does trigger The change introduced in 1.12 is very good, as the current behaviour - even though it is valid according to JaxRS specification - IMO breaks the principle of least astonishment. |
Hi @lwitkowski, And how could this: I even put a try-catch around the caller and a breakpoint in the catch block to check the value of the received response entity contained in the exception and it's null, as expected. At this point it seems that a EDIT: Anyway, since the behavior of all this should be different as of 1.12, maybe it's not worth wasting any more time on this. |
@Faboli7 You're right about reproducer, I used 1.12 for some reason :-/ With 1.11 it does bypass Exception Mapper, and here's the reason: Between ResourceB and ServiceB there's whole network stack, and Does that make sense now? |
@lwitkowski Thanks, at least I have the technical explanation now. I'm not sure I understand why an automatic Response from resteasy (like 405) is treated differently though, as there is also network involved (ServiceB has a GET method, ResourceB exposes a HEAD method so ServiceB sends a GET request that goes over the network as well, except that there is no corresponding endpoint in ResourceB (no GET endpoint) so resteasy returns a 405, and this triggers the mapper. Anyway it's just because I like to understand how things work. In my real project the API I call is not even written in java so I don't know what would be the behavior with an empty body (I never tested it, as the whole point of my mapper was to remove the body from the error responses of this API before forwarding them to the frontend). So in conclusion, I don't know if this behaves as expected or not in the end, but since 1.12 handles things differently (and most importantly, the way I wanted), I don't want to bother you any longer so in my opinion we can close the issue and I'll just upgrade to 1.12 (I'm currently trying but I have issues with calls to azure on startup, seems like a conflict between netty versions in quarkus and azure. I'll open another issue if I can't manage to solve it). Thanks all for your time. |
@Faboli7: Response to |
@gsmet, @kenfinnigan: Consider closing this one - as of reporter suggestion 😃 |
Closing at reporters request |
Describe the bug
Hi,
According to the respective documentations, rest-client provides a default
ResponseExceptionMapper
that will transform any response with status >= 400 into aWebApplicationException
.Jax-rs on its side, provides a default
ExceptionMapper
forWebApplicationException
that will convert them into the appropriate response.This means that in a project using both, if an external service called with a rest client returns an error response, it will be mapped to a WAE that the jax-rs part of my application will remap to a Response before sending it to the client of my app. And it seems to be what happens, as my jax-rs endpoints return exactly the error response that was received by the rest client.
Now my issue is that I want to override the default ExceptionMapper for WAE. So I wrote my own, but it's never executed, even if I add
@Priority(1)
as advised in this issue.Here's the code just to be sure:
I know that the default
ResponseExceptionMapper
from rest-client works fine because I'm able to catch the WAE in a try-catch block around the call of the client interface method.I also have other
ExceptionMapper
s in my project that work just fine.I suspect a conflict with the default mapper, although
@Priority
is supposed to fix it.But what is even weirder is that if I create my own exception (and implement and register the corresponding
ResponseExceptionMapper
in my rest clients to return it), it works as expected, but only if my exception extendsRuntimeException
. It doesn't work if it extendsWebApplicationException
.Anyway this workaround works but it's not as elegant as I have to register this custom
ResponseExceptionMapper
in all my rest-clients with@RegisterProvider
+ since I can't extend WAE directly, I need to kind of reimplement its behavior myself in my custom exception. Also, I don't really like the idea of modifying the rest client part to make jax-rs work as expected.Also worth mentioning, this happens no matter if I'm running the dev profile or any other profile.
Expected behavior
My custom ExceptionMapper should be triggered instead of the default one.
Actual behavior
My custom ExceptionMapper is ignored.
To Reproduce
Steps to reproduce the behavior:
Environment (please complete the following information):
uname -a
orver
: (but also happens in production on alpine linux)MINGW64_NT-10.0-19042 BEKST00080 3.1.7-340.x86_64 2020-10-23 13:08 UTC x86_64 Msys
java -version
:openjdk 11.0.7 2020-04-14 LTS
OpenJDK Runtime Environment 20.4-(Zulu-11.39+15-win_x64)-Microsoft-Azure-restricted (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM 20.4-(Zulu-11.39+15-win_x64)-Microsoft-Azure-restricted (build 11.0.7+10-LTS, mixed mode)
mvnw --version
orgradlew --version
): maven 3.6.3The text was updated successfully, but these errors were encountered: