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

Wrap DecodingException thrown by WebFlux functional endpoints #22290

Closed
bclozel opened this issue Jan 22, 2019 · 1 comment
Closed

Wrap DecodingException thrown by WebFlux functional endpoints #22290

bclozel opened this issue Jan 22, 2019 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented Jan 22, 2019

In Spring WebFlux, reading an invalid request body can result in a DecodingException thrown by the codec.

In the annotation variant, this exception is wrapped in a ServerWebInputException in ArgumentResolver implementations. Since ServerWebInputException extends ResponseStatusException, this is automatically handled by the error handling mechanism as an HTTP 400 response status.

Right now in the functional variant, the DecodingException bubbles up and causes an HTTP 500 error since it's not expected by the error handling infrastructure.

The DecodingException Javadoc mentions:

For example in server web application, a DecodingException would
translate to a response with a 400 (bad input) status while
CodecException would translate to 500 (server error) status.

@poutsma, I think we should align WebFlux functional with the annotation variant here; doing so in BodyExtractors is not the right choice since this class can be used on both server and client side.
Since this behavior is expected by the error handling infrastructure, should we introduce this exception mapping in HandlerFunctionAdapter? Or is there a better place for that?

@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug status: pending-design-work Needs design work before any code can be developed labels Jan 22, 2019
@bclozel bclozel added this to the 5.1.5 milestone Jan 22, 2019
@poutsma
Copy link
Contributor

poutsma commented Jan 22, 2019

If we do it in the adapter then the error handling will not apply in "standalone" mode (i.e. using RouterFunctions.toWebHandler and not the DispatcherHandler). I am thinking that DefaultServerRequest.bodyInternal is a better place, as that's used by all body variants.

@bclozel bclozel self-assigned this Jan 22, 2019
@bclozel bclozel removed the status: pending-design-work Needs design work before any code can be developed label Jan 22, 2019
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: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants