Skip to content

Inconsistent error response when problemdetails enabled #33885

Open
@jonatan-ivanov

Description

@jonatan-ivanov

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions