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

Add types to represent RFC 7807 problem details and exceptions #28187

Closed
Tracked by #27052
rstoyanchev opened this issue Mar 16, 2022 · 1 comment
Closed
Tracked by #27052

Add types to represent RFC 7807 problem details and exceptions #28187

rstoyanchev opened this issue Mar 16, 2022 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Mar 16, 2022

The goal for this issue is to add a representation for an RFC 7807 problem detail, and integrate it into Spring MVC and Spring WebFlux error response handling.

On the WebFlux side we have the ResponseStatusException hierarchy which contains HTTP status, a reason, and headers. We can now add a ProblemDetail as the body. This provides full encapsulation of all error response details within the exception.

On the Spring MVC side, we have the DefaultHandlerExceptionResolver which maps exceptions to HTTP status and headers, so exceptions do not themselves contain that information. Furthermore the exception hierarchy does not have a single base class where this can be added. We can add an interface to represent an error response, e.g. ErrorResponse, similar to the information exposed from ResponseStatusException on the WebFlux side, and then have all Spring MVC exceptions implement it in order to expose it in which case DefaultHandlerExceptionResolver no longer needs mapping logic.

ResponseEntityExceptionHandler is a base class for a controller advice that uses an @ExceptionHandler method to render error details. It has been around for some time, but so far application have had to extend it to decide on the error body format. We can now fill in the blank and use ProblemDetail for ResponseError exceptions that expose such information. A similar class does not exist for WebFlux but can be added.

ResponseEntity handling for both Spring MVC and WebFlux should support ProblemDetail and ErrorResponse as return types, automatically setting the response status, headers, and body accordingly. This is also an opportunity to set the instance field of ProblemDetail to the request path as a fallback if instance hasn't been set.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Mar 16, 2022
@rstoyanchev rstoyanchev added this to the 6.0.0-M3 milestone Mar 16, 2022
@rstoyanchev rstoyanchev self-assigned this Mar 16, 2022
@rstoyanchev
Copy link
Contributor Author

See commits linked the umbrella issue #27052.

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

No branches or pull requests

1 participant