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

Inconsistent error response when problemdetails enabled #33885

Open
jonatan-ivanov opened this issue Jan 18, 2023 · 1 comment
Open

Inconsistent error response when problemdetails enabled #33885

jonatan-ivanov opened this issue Jan 18, 2023 · 1 comment
Labels
status: pending-design-work Needs design work before any code can be developed theme: web-error-handling type: enhancement A general enhancement
Milestone

Comments

@jonatan-ivanov
Copy link
Member

jonatan-ivanov commented Jan 18, 2023

Affects: Boot 3.0.1, Framework 6.0.3

With the current version (Boot 3.0.1, Framework 6.0.3), if Problem Details are enabled (spring.mvc.problemdetails.enabled=true) and if I throw out an error from an MVC controller method, sometimes I get a Problem Details response, sometimes I get the "old" (Boot 2.x, Framework 5.x) response format depending on the default error handler "knows" the exception or not.

@GetMapping("/")
public String trouble() {
	// throw new IllegalStateException("Noooooo!"); // "old" (5.x) response
	throw new ResponseStatusException(INTERNAL_SERVER_ERROR, "Noooooo!"); // -> problem details response
}

When I throw IllegalStateException

HTTP/1.1 500
Connection: close
Content-Type: application/json
Date: Wed, 18 Jan 2023 21:34:42 GMT
Transfer-Encoding: chunked

{
    "error": "Internal Server Error",
    "path": "/",
    "status": 500,
    "timestamp": "2023-01-18T21:34:42.764+00:00"
}

When I throw ResponseStatusException

HTTP/1.1 500
Connection: close
Content-Type: application/problem+json
Date: Wed, 18 Jan 2023 21:35:04 GMT
Transfer-Encoding: chunked

{
    "detail": "Noooooo!",
    "instance": "/",
    "status": 500,
    "title": "Internal Server Error",
    "type": "about:blank"
}

I think the expected behavior would be a consistent response format; application/problem+json if problem details enabled and the old (5.x) application/json format if not.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 18, 2023
@bclozel bclozel transferred this issue from spring-projects/spring-framework Jan 19, 2023
@bclozel bclozel added type: enhancement A general enhancement theme: web-error-handling and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 19, 2023
@bclozel
Copy link
Member

bclozel commented Jan 19, 2023

We've added support for ProblemDetail in #32634 with a configuration flag. This support was brand new at the time and we wanted to introduce it progressively to avoid too much user facing changes in Spring Boot 3.0. Right now the Spring Boot error handling format does not use the ProblemDetail format and we will expand the support in #19525, and possibly revisit more generally our error handling support in light of what's supported now in Spring Framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending-design-work Needs design work before any code can be developed theme: web-error-handling type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants