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

Auto-configure ProblemDetails support for Spring MVC and Spring WebFlux #32634

Closed
bclozel opened this issue Oct 7, 2022 · 2 comments
Closed
Assignees
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented Oct 7, 2022

As of spring-projects/spring-framework#27052, Spring Framework provides support for the "Problem Details" RFC 7807.
This is supported for both Spring MVC and Spring WebFlux, backed by ResponseEntityExceptionHandler.

We should introduce configuration properties (spring.mvc.problemdetails.enabled and spring.webflux.problemdetails.enabled) that contribute custom ResponseEntityExceptionHandler instances (annotated with @ControllerAdvice) so that ProblemDetail and related exceptions are handled properly and serialized as application/problem+json.

We should ensure that:

  • those properties are false by default, as this could be a breaking change for applications
  • those beans are not configured if a ResponseEntityExceptionHandler is already present in the context
@bclozel bclozel added this to the 3.0.0-RC1 milestone Oct 7, 2022
@bclozel bclozel self-assigned this Oct 7, 2022
@bclozel bclozel closed this as completed in 23a9818 Oct 7, 2022
@vpavic
Copy link
Contributor

vpavic commented Oct 7, 2022

Are there plans to make application/problem+json the default format for error responses in the future? I think something based on standards is always a more suitable default vs something non-standard.

However, it seems that such a change wouldn't be considered until 4.0 which is I assume years away.

Could you still consider changing the default for 3.0? It is a major release after all, and flipping one configuration property to restore previous behavior doesn't seem like a big deal.

@bclozel
Copy link
Member Author

bclozel commented Oct 7, 2022

There are no plans currently for this. The Problem Details support is completely new, and this also changes the response format. We would also probably need to deprecate/remove existing infrastructure such as ErrorController and ErrorAttributes. The current problem details feature supports internationalization, but HTML view rendering is not (like with Boot's error handling).

We're definitely considering this option and we will probably gradually improve and replace things during the 3.x timeline. We definitely need more feedback on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants