Closed alxxyz closed 1 year ago
Hi @alxxyz
By default, the DispatcherServlet does not throw a NoHandlerFoundException. You need to enable that:
Check if you have right configuration in your application.properties.
spring.mvc.throw-exception-if-no-handler-found=true
Besides, if you are using @EnableWebMvc then it is likely that your changes made, for example, in properties files will be overwritten. https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-servlet-config
I am using Webflux instead of WebMvc, does it work also for Webflux?
@alxxyz that should be the case out of the box in WebFlux, in DispatcherHandler.
@rstoyanchev can you please advise how I can catch it and override the response?
As I can not catch it in the @ControllerAdvice
@alxxyz, catching early exceptions from before a handler is chosen was added recently for 6.0 with #22991, so it's not supported in 5.3.x. Are you trying to add a body to the error response or something else?
Yes, we have an API contract and I need to send a custom body
I see, so that's supported from 6.0 onwards. In 5.3.x, you can use a WebExceptionHandler
as a workaround, or Boot's error handling.
Thank you @rstoyanchev
How to throw exception if no handler found in Webflux?