Currently ErrorController will produce traditional error response even if problem details is enabled, nobody want to mix two different style of error handling.
@RequestMapping("/")
void home(HttpServletResponse response) throws IOException {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "bad.request");
}
@Test
void sendErrorShouldProduceProblemDetails() {
ResponseEntity<Map<String, Object>> resp = testRestTemplate.exchange(RequestEntity.method(GET, "/").build(),
new ParameterizedTypeReference<Map<String, Object>>() {
});
assertThat(resp.getBody()).containsKey("detail");
}
Expecting actual:
{"error"="Bad Request", "message"="bad.request", "path"="/", "status"=400, "timestamp"="2023-04-06T02:01:46.401+00:00"}
to contain key:
"detail"
Here is minimal project problemdetails.zip
Comment From: snicoll
Thanks for the report, this is a duplicate of #33885