spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.59k stars 40.55k forks source link

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

Closed bclozel closed 1 year ago

bclozel commented 1 year ago

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:

vpavic commented 1 year ago

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 commented 1 year ago

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.