Handle case where ResponseEntity
and ProblemDetail
don't agree on the HTTP status to use
#29378
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
ResponseEntity
has a dedicated methodResponseEntity.of(ProblemDetail)
, which uses the status property ofProblemDetail
and returns a builder to add headers, or one can also return justProblemDetail
, if there is no need to add headers. However, ifResponseEntity
wraps aProblemDetail
as any other body, i.e. not using the dedicated method, and the status from theResponseEntity
which actually sets the response, could be mismatched with the one listed in the body.One option would be to reject this, but than a 500 error would obscure the original problem, and would only be discovered at runtim. In that sense, it might be better for the client to get a response with the status from the
ResponseEntity
, even if the body details, which should be informational, don't agree.Perhaps the best middle ground would be to log a warning to ensure this is noticed proactively, while the client still has a better chance of handling the response than they would with a 500.
The text was updated successfully, but these errors were encountered: