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

Support for customization of 404 response when RouterFunctionWebHandler finds no routes #25358

Conversation

ivd-git
Copy link
Contributor

@ivd-git ivd-git commented Jul 6, 2020

Context
Next to the default WebServer a service starts another server to handle admin requests on a different port. The admin webserver is connected to the HttpHandler created by RouterFunctions.toHttpHandler.

When the admin server processes a request for a path not mapped to any RouterFunction then the admin server responds with a 404 NotFound status code and an empty response body.

Currently it is not possible to have a different response body.

Changing the RouterFunctionWebHandler to return a Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND)) instead of ServerResponse.notFound().build() allows clients to implement an exception handler that customizes the response body.

Default behavior does not change because WebFluxResponseStatusExceptionHandler is the default handler.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 6, 2020
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 11, 2021
@poutsma poutsma self-assigned this Dec 2, 2021
@poutsma poutsma changed the title Support for customization of NotFound response when RouterFunctionWebHandler finds no routes Support for customization of 404 response when RouterFunctionWebHandler finds no routes Dec 3, 2021
@poutsma poutsma added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 3, 2021
@poutsma poutsma added this to the 5.3.14 milestone Dec 3, 2021
poutsma pushed a commit that referenced this pull request Dec 3, 2021
This commit makes it possible to customize 404 responses generated by
RouterFunctionWebHandler, by throwing an ResponseStatusException
instead of returning a standard 404 response.

See gh-25358
poutsma added a commit that referenced this pull request Dec 3, 2021
…und-to-exception-pr

* gh-25358:
  Polish "Throw 404 ResponseStatusException when no routes found"
  Throw 404 ResponseStatusException when no routes found
@poutsma
Copy link
Contributor

poutsma commented Dec 3, 2021

Merged in 2f557d9.

Thank you for submitting a PR, and we are sorry it took this long to resolve.

@poutsma poutsma closed this Dec 3, 2021
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) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants