-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Handle ResponseStatusException thrown by MVC functional endpoints #32689
Comments
Any Progress? I really hope to see this problem being fixed in 6.2.0. |
This topic has been worked on in the past already. With #22619 in 5.3, we have made it possible to handle exceptions from any handler if you configure the Later with #26772 in 6.1.2, we added a Here, this issue points to the fact that while this is now possible to handle exceptions from a function handler in MVC, it's not consistent with the behavior in WebFlux. With WebFlux, exceptions raised by functional handlers are processed by the If the handler function is registered as a lambda, the resolver will not be able to find the enclosing type. On the other hand, I'm wondering if declaring the handler function as a type itself would mean that the infrastructure would look for annotated methods on that type directly? That could be indeed strange. You can opt-in for this behavior quite easily in Spring Boot with the following:
If we want behavior parity with WebFlux, I guess we could update |
Spring MVC and WebFlux evolved in slightly different ways. The So, both already support use of |
@bclozel I followed your suggestion and while your registration works, the controller advice stopped handling exceptions for annotated controllers. The application has both annotated controllers and router functions (non annotated controllers) and without the custom registration @ControllerAdvice doesn't work for non annotated controllers, but it works annotated Controllers. With your registration @ControllerAdvice stopped working for annotated controllers and started working for RF. Any suggestion? |
@thiagolocatelli Yes, I believe the following would work:
|
@thiagolocatelli Right, sorry I mislead you. This feature is indeed built to give you finer control. In your case, chances are returning |
I am customizing HandlerFunction:
For web MVC:
For web Flux:
I expect that the ResponseStatusException should be handled by
ResponseEntityExceptionHandler
(when settingspring.{mvc,webflux}.problemdetails.enabled
to true), but the result is that the exception in ReactiveHandlerFunction can be handled, while the one in ServletHandlerFunction cannot. The reason is found here (org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#shouldApplyTo
), where exceptions thrown from HandlerFunction are not processed.This is somewhat frustrating, especially when developing frameworks. I hope that both webmvc and webflux can have the same behavior for exception handling. It would be really helpful if
ExceptionHandlerExceptionResolver
could handleResponseStatusException
thrown by HandlerFunction.The text was updated successfully, but these errors were encountered: