抛出异常时,以下代码应返回带有相应文本的错误,因为他们写https://www.baeldung.com/spring-response-status-exception
@GetMapping
public ResponseEntity<FeedbackDto> get(@RequestHeader(value = "user-token") String userToken) {
try {
return ResponseEntity.ok().body(feedbackService.getByUserToken(userToken));
} catch (UserNotFoundException ex) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "User Not Found. Id=" + ex.getMessage());
}
}
我和邮递员核对。来了
{
"timestamp": "2020-08-05T15:53:49.120+00:00",
"status": 404,
"error": "Not Found",
"message": "",
"path": "/feedback"
}
根据Spring Boot version 2.3+的en-SO,您需要将其添加到以便始终显示错误:
application.properties