When I throw a ResponseStatusException
, I get a completely empty body. Just {}
. I'm still getting the correct error code. I'm not using any ControllerAdvice
annotiations anywhere and I added server.error.include-message=always
to the application.properties
file. I notice that other people have an issue where they have an empty message such as with:
{
"timestamp": "2021-1-26T12:34:26.416+00:00",
"status": 404,
"error": "Not Found",
"message": "",
"path": "/hello"
}
but I don't even get a body. This is what the method in my controller looks like. I have other methods in the same controller that will return responses to the client with the correct body, just not when exceptions are thrown. Currently using Spring Boot 2.3.7
@GetMapping("/error")
public String testError() {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Invalid");
}
question from:
https://stackoverflow.com/questions/65650369/throwing-responsestatusexception-in-controller-returns-no-body 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…