Sud*_*aka 32 java spring spring-boot
我已经处理过这样的未经授权的异常
@ResponseStatus(value= HttpStatus.UNAUTHORIZED)
public class UnauthorizedException extends RuntimeException {
public UnauthorizedException(String message) {
super(message);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我抛出如下错误时
throw new UnauthorizedException("Invalid credentials");
Run Code Online (Sandbox Code Playgroud)
我在响应中收到错误消息为空,如下所示
{
"timestamp": "2020-05-27T13:44:58.032+00:00",
"status": 401,
"error": "Unauthorized",
"message": "",
"path": "/auth/register"
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用,
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Invalid credentials");
Run Code Online (Sandbox Code Playgroud)
但结果还是一样。当我添加spring-boot-devtools依赖项时,我也按预期通过堆栈跟踪收到消息。我怎样才能解决这个问题?
Spring 版本:2.3.0 Java 版本:11.0
Art*_*ttu 59
好的,他们已将 server.error.include-message 的默认值更改为“从不”(请参阅此处的评论部分:Spring 2.3.0 Release Info
此处列出了所有默认值: Spring Boot 参考文档
只需像这样配置您的 application.yaml(或属性)。
server:
error:
include-message: always
include-binding-errors: always
Run Code Online (Sandbox Code Playgroud)
请注意,显示错误消息可能会泄露有关您的服务器实现的信息。
归档时间: |
|
查看次数: |
5326 次 |
最近记录: |