-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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 problem details based on RFC 7807 #27052
Comments
Spring HATEOAS includes another VndErrors API, it is based on https://github.com/blongden/vnd.error. |
ProblemDetail is a representation of an RFC 7807 "problem", and this commits adds support for it in Spring MVC and WebFlux as a return value from `@ExceptionHandler` methods, optionally wrapped with ResponseEntity for headers. See gh-27052
ErrorResponse represents a complete error response with status, headers, and an RFC 7807 ProblemDetail body. ErrorResponseException implements ErrorResponse and is usable on its own or as a base class. ResponseStatusException extends ErrorResponseException and now also supports RFC 7807 and so does its sub-hierarchy. ErrorResponse can be returned from `@ExceptionHandler` methods and is mapped to ResponseEntity. See gh-27052
All Spring MVC exceptions from spring-web, now implement ErrorResponse and expose HTTP error response information, including an RFC 7807 body. See gh-27052
DefaultHandlerExceptionResolver now supports ErrorResponse exceptions and can map them to HTTP status and headers of the response. This includes not only exceptions from spring-web, but also any other exception that implements ErrorResponse. ResponseEntityExceptionHandler is updated along the same lines, now also handling any ErrorResponseException. It can be used it for RFC 7807 support for Spring MVC's own exceptions. See gh-27052
@rstoyanchev, I have reviewed the commits so far and they look great! 💯 Thanks so much for working on this issue. 🙇 Given our experiences with RFC 7807 I shared earlier, I would like to share some remarks: Loss of information while deserializing
|
@vy thanks for the review and comments. For For For mutability, indeed immutable would be my preferred choice, but I'm just thinking, (de-)serialization friendliness aside, that the case here is rather specific. We're talking about an exception type, or a type carried within an exception that short-circuits regular handling and follows a straight line towards being serialized to the response body. Moreover, there are already reasons to allow mutability, such as when a |
Thanks so much for the prompt reply @rstoyanchev. (Apologies for my late reaction; vacation + other priorities get in my way.)
I am not able to follow your reasoning here. Libraries will expect a
I see your point regarding the questions about how to customize or eliminate
Sorry, but I couldn't follow. Would you mind elaborating on this, please? (I know what
Again, I am not able to follow. If
Mind sharing a more tangible example on how mutability of |
@vy my turn to apologize for not coming back to this until now. I've created a sample project. It demonstrates use of
On the client side, we will provide some conveniences in #28190 to be able to decode the error response body to a target class. This could be Apologies for not answering your questions directly, but I'm hoping the sample helps to provide more context, and we can continue with questions from there. One comment/question to you. For you suggestion to add |
For dynamic properties, I've created #28665. |
I'm wondering if it would make sense to move the I've seen libraries often using |
As an HTTP abstraction, |
ProblemDetail is intended to be extended with additional fields. This commit removes its "with" methods for chained initialization to keep it as plain as possible and avoid imposing a particular style on subclasses. See gh-27052
@vy and @wimdeblauwe, the work under #28814 to allow external customization, including internationalization, of the "detail" for Spring MVC / WebFlux and for any |
All tasks are now complete. |
@rstoyanchev, this PR is in our roadmap and we will extensively review it in a week or two. I will really appreciate it if you can allow us some time. |
Linking here to a related discussion for the class name |
For everyone following here, there is a specific corner case described in #29378. |
This has been requested a number of times but so far has been deferred to Spring Boot which supports error response details. The corresponding spring-projects/spring-boot#19525 issue in Spring Boot has gathered quite a bit of feedback and comments.
For Spring Framework 6 we have an opportunity to revisit this topic and more generally, web error handling. Given a standard such as RFC 7807 for the format of error responses, the Spring Framework could provide more infrastructure that Boot can build on.
The text was updated successfully, but these errors were encountered: