Skip to content
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

Throw exception if no handler found in Webflux #29568

Closed
alxxyz opened this issue Nov 24, 2022 · 8 comments
Closed

Throw exception if no handler found in Webflux #29568

alxxyz opened this issue Nov 24, 2022 · 8 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@alxxyz
Copy link

alxxyz commented Nov 24, 2022

How to throw exception if no handler found in Webflux?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 24, 2022
@jaDEVirek
Copy link

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

@alxxyz
Copy link
Author

alxxyz commented Nov 25, 2022

I am using Webflux instead of WebMvc, does it work also for Webflux?

@rstoyanchev
Copy link
Contributor

@alxxyz that should be the case out of the box in WebFlux, in DispatcherHandler.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Nov 25, 2022
@rstoyanchev rstoyanchev added this to the Triage Queue milestone Nov 25, 2022
@alxxyz
Copy link
Author

alxxyz commented Nov 29, 2022

@rstoyanchev can you please advise how I can catch it and override the response?
As I can not catch it in the @ControllerAdvice

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 29, 2022
@rstoyanchev
Copy link
Contributor

@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?

@alxxyz
Copy link
Author

alxxyz commented Nov 30, 2022

Yes, we have an API contract and I need to send a custom body

@rstoyanchev
Copy link
Contributor

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.

@rstoyanchev rstoyanchev closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2022
@rstoyanchev rstoyanchev added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Nov 30, 2022
@rstoyanchev rstoyanchev removed this from the Triage Queue milestone Nov 30, 2022
@alxxyz
Copy link
Author

alxxyz commented Nov 30, 2022

Thank you @rstoyanchev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

4 participants