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

Consider not handling NoResourceFoundException in WebFlux #34236

Open
bclozel opened this issue Jan 10, 2025 · 2 comments
Open

Consider not handling NoResourceFoundException in WebFlux #34236

bclozel opened this issue Jan 10, 2025 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@bclozel
Copy link
Member

bclozel commented Jan 10, 2025

While working on ProblemDetail support for error views in Spring Boot (See spring-projects/spring-boot#19525), I have noticed that the org.springframework.web.reactive.result.method.annotation.ResponseEntityExceptionHandler handles all NoResourceFoundException instances as Problem Detail JSON/XML responses.

This exception is thrown for all 404s in the application, meaning that a browser requesting a missing page will always get a JSON response.

In the current error handling support for Spring Boot, the application can contribute an ErrorWebExceptionHandler which can render errors as JSON payloads or HTML views. Because it is ordered after the ResponseEntityExceptionHandler, there is no chance for Spring Boot to render HTML error pages for 404s.

I don't think there is a way to really understand the intent of the client here in Spring Framework. Spring Boot does that by checking that the client requests "text/html" explicitly.

This is an important change to consider in 6.2.x, but I'm wondering how we can unlock this use case for Spring Boot. Isn't handling

@bclozel bclozel added status: waiting-for-triage An issue we've not yet triaged or decided on in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 10, 2025
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jan 13, 2025

Spring Boot has been able to do content negotiation for error handling through @RequestMapping methods, but the same was not possible with just @ExceptionHandler methods. Now that #31936 has made that capability available, we can revisit the ResponseEntityExceptionHandler setup, which is intended only for HTTP services, and provide something similar that would apply to "text/html" requests. That way we can provide handling of the same exceptions for HTTP services and browser clients similar to what Boot does.

@bclozel
Copy link
Member Author

bclozel commented Jan 13, 2025

I've considered this a bit and I have a few questions:

  • browsers send accept headers like text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8. The "/" part means that the ordering of exception handlers is key.
  • does this mean that Spring Boot should then extend/replace this HTML error handling in the future? Spring Boot has a quite evolved mechanism that renders static pages and views.
  • if we want to move things forward, Consider using RFC 7807 problem details for error responses spring-boot#19525 needs to happen for Spring Boot 3.5 (which is Framework 6.2 based). That puts a lot of pressure on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

2 participants