We are using spring boot backend service and require to publish custom status code and status message in response. As per current spec spring supports sending custom status code in ResponseEntity's builder ResponseEntity.status(int statusCode) but doesn't have a mechanism to send custom status message along with it.
Sending the code and status message in the response body isn't an option for our use case.
Comment From: bclozel
I'm not sure this is something we can support.
The Servlet API provides setStatus(int sc)
for non-error statuses and void sendError(int sc, String msg)
for errors - those triggger the Servlet container error page, I'm not sure if the message is written on the HTTP status line.
If you can show a consistent way to achieve that with plain Servlet API we can consider it. Could you give it a try?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: bclozel
After reviewing possible solutions, I'm closing this issue.
The Servlet API doesn't allow setting the message on the status line - as said previously, the void sendError(int sc, String msg)
will trigger an error HTML page with the provided message. This is defined in the Servlet spec, so there's no way around it.
If you'd like to to provide custom error messages, you can add them in the response body (as serialized JSON, for example). Spring Boot is returning such errors to HTTP clients. We're also consider existing specs for error messages in #27052.
Thanks!