-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
RESTEasy ExceptionMapper is not called when using Hibernate Validator on QueryParams #12006
Comments
/cc @gsmet |
Unless I am reading this wrong, I am pretty sure what you are seeing is the desired behavior, because JAX-RS will use the ExceptionMapper whose generic type best matches the exception - which is So to get the described behavior, you need to use the specific exception type you want to handle in your exception mapper. @gsmet do you agree? If so, we can close this issue. |
@geoand thanks, it makes sense. What I was trying to achieve is to have a central exception mapper, assuming that it would override all exception mappers, instead of creating a separate class for each exception type and having other handlers working in the background without being clearly visible for whoever has to maintain the code after me. |
Yeah, I don't think you can do that AFAIK |
I don't know if |
CC @ronsigal |
I also tried to define a "catch-all" style ExceptionMapper and ran into this issue. @priority didn't do the trick for me. There are many different ExceptionMappers defined on the classpath that "overtake" exceptions and return all sorts of weird and unpredictable responses. This is undesirable behavior, especially when trying to standardize an API error response format. |
Thank you for the information. Can you please check that? I can't find anything about that class. Also, when just getting the 400 response, it's hard to find out how to change it, so it should be documented -- I guess in the validation guide. |
Check what exactly?
I'm not really following here, can you explain? |
The name of the class you mentioned. As my links show, there's no such class in the Quarkus source code. But meanwhile, I think you meant
Sorry. As a developer using Quarkus, when I see that my application returns just the However, without googling and finding your hint here on the GitHub issue, it would've been hard for me to know that I need to implement a |
You are absolutely right, I was thinking a few days into the future :)
This is a good point because although this is standard JAX-RS behavior, however it probably does make sense to mention this. @gsmet as this is your wheelhouse, WDYT? |
Closing as this is a question instead of a bug. Moreover I opened #43592 to enhance the docs. |
Add note about `ExceptionMapper<ValidationException>` in validation guide
Relates to: quarkusio#12006 (cherry picked from commit fa187a7)
Describe the bug
When using Hibernate validator to check query parameters in a RestEasy endpoint the validation error is returned before it could be caught and altered by a custom ExceptionMapper.
Expected behavior
ExceptionMapper should catch and be able to override all exception responses in the controller.
Actual behavior
The hibernate validation error response is returned to the caller without even calling the ExceptionMapper.
To Reproduce
ExceptionMapper. I'm using "not implemented" as the default exception to be easy to spot in the response.
Case 1: Controller with Hibernate Validator:
When calling it without a @QueryParam (violating @NotNull) the default Hibernate response is returned,
not calling ExceptionMapper at all:
Case 2: Controller without a Hibernate Validator:
When calling it and running into any exception during execution they will be properly caught and handled by the ExceptionMapper:
http :8080/hello HTTP/1.1 501 Not Implemented Content-Length: 16 Content-Type: text/plain;charset=UTF-8 custom exception
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: