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

Render global errors as Problem Details #43850

Open
bclozel opened this issue Jan 16, 2025 · 6 comments
Open

Render global errors as Problem Details #43850

bclozel opened this issue Jan 16, 2025 · 6 comments
Labels
type: enhancement A general enhancement
Milestone

Comments

@bclozel
Copy link
Member

bclozel commented Jan 16, 2025

Spring Boot handles errors globally as JSON responses or HTML pages. This is powered by ErrorController and ErrorAttributes.

Spring Framework added support for Problem Details and Spring Boot auto-configures this as of #32634.

This issue is about rendering global errors in the problem details format consistently, as well as providing a path forward to making this the default in the future. This means that ErrorAttributes would need to produce a ProblemDetail or ErrorResponse instead of a Map. Also, we would probably need to revisit the backing infrastructure to better align with Framework. There are upcoming changes in Framework that could help us to improve the support and make it more lightweight, see spring-projects/spring-framework#34272.

@kiruthiga1793
Copy link

Hi @bclozel , I would like to collaborate. Can I work on this issue?

@bclozel
Copy link
Member Author

bclozel commented Jan 17, 2025

@kiruthiga1793 Thanks for the proposal but the issue is already assigned and I have a good chunk of changes ready. We're waiting for changes in Framework to complete this work.

@kiruthiga1793
Copy link

@bclozel Thanks for letting me know. Add me also next time if possible if the issue has some sub tasks.

@danielrohe
Copy link

Hi Brian,

in our company we implemented ErrorAttributes and ErrorView in a way that the Map structure resembled the JSON Problem structure for all spring framework exceptions and also added extension points for individual other exceptions. So I'm curious about the new improvement that come with Spring Framework and the way how exception handling will change in Spring Boot.

@bclozel
Copy link
Member Author

bclozel commented Jan 31, 2025

@danielrohe Is your application enabling problem details support in Spring Boot with the spring.mvc.problemdetails.enabled=true property? This should take care of handling most exceptions thrown by Spring Framework and render them as Problem Details responses in JSON or XML format with i18n support.

Currently, exceptions that are not handled at this point escape to the global Spring Boot error handling and are rendered as traditional Spring Boot errors. The goal of this issue if to make those problem details responses. Note, Spring Framework must first extend its error rendering support to render HTML error pages spring-projects/spring-framework#34272.

Hopefully once this is all done, you won't have to maintain this custom error handling setup anymore as this will all be done for you.

@danielrohe
Copy link

danielrohe commented Jan 31, 2025

Hi Brian,

no, we didn't use Spring Framework's ProblemDetails support We implemented this approach of overwriting ErrorAttributes and ErrorView before Spring Framework supported Problem Details. This solution worked out quite well for all Spring Framework exceptions and also others like javax-validation's ConstraintViolationException for services that serve JSON and web (HTML) traffic. In addition we also have a Problem Details implementation at https://github.com/zalando/problem-spring-web that served pure backend services just serving JSON. For these services we can replace it with Spring Framework's Problem Details support as the responses are mostly similar. For the services that serve JSON and HTML we are using our implementation because the current Spring Framework does not support serving web (HTML) traffic. Therefore I'm curious what this new implementation will bring and whether its possible for users to utilize it for other framework exceptions like javax-validation's ConstraintViolationException.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants