Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

java - Throwing ResponseStatusException in controller returns no body

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...