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

Support "application/problem+json" as the response Content-Type #28189

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

Support "application/problem+json" as the response Content-Type #28189

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

Once #28187 provides ProblemDetail along with the ErrorResponse hierarchy of exceptions that encapsulate HTTP status, headers, and body, to support RFC 7807, it is also necessary to improve content negotiation and formatting specifically for error responses.

In Spring MVC it is possible to configure content type resolution and message conversion and likewise in WebFlux to configure content type resolution and message codecs, but those apply to both @RequestMapping and @ExceptionHandler methods.

Error handling however has a different perspective. The range of supported media types might be more limited and different, e.g. only application/problem+json. The resolution of the request content type might also be done differently, .e.g. defaulting to application/problem+json if not explicitly requested, or perhaps even enforcing it.

Such a mechanism is also a convenient place for other configuration related to how ProblemDetail should be rendered..

@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-M4 milestone Mar 16, 2022
@rstoyanchev rstoyanchev self-assigned this Mar 16, 2022
@rstoyanchev
Copy link
Contributor Author

On closer investigation, this can be handled transparently as follows.

Message converters and encoders indicate a preference for application/problem+json when ProblemType is serialized. This ensures application/problem+json is preferred when the client is flexible or has no preference.

If content negotiation fails to find an acceptable media type for serializing ProblemDetail, we try again with application/problem+json and application/problem+xml as the acceptable media types, in effect enforcing a fallback for ProblemDetail.

@rstoyanchev rstoyanchev changed the title WebMvc and WebFlux config for content negotiation and encoding of error responses Support "application/problem+json" as the response Content-Type May 9, 2022
rstoyanchev added a commit that referenced this issue May 9, 2022
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