我的boot版本是:2.3.12.RELEASE
问题:自定义异常message返回为空
解决方式:
server:
# 自定义异常返回
error:
include-message: always
结果:
问题说明
这里的message是有值的
进入下一个方法
public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
Map<String, Object> errorAttributes = getErrorAttributes(webRequest, options.isIncluded(Include.STACK_TRACE));
if (Boolean.TRUE.equals(this.includeException)) {
options = options.including(Include.EXCEPTION);
}
if (!options.isIncluded(Include.EXCEPTION)) {
errorAttributes.remove("exception");
}
if (!options.isIncluded(Include.STACK_TRACE)) {
errorAttributes.remove("trace");
}
if (!options.isIncluded(Include.MESSAGE) && errorAttributes.get("message") != null) {
errorAttributes.put("message", "");
}
if (!options.isIncluded(Include.BINDING_ERRORS)) {
errorAttributes.remove("errors");
}
return errorAttributes;
}
发现问题这里的判断会把message覆盖
通过百度得知
翻译得知
更改默认错误页面的内容默认情况下,错误消息和任何绑定错误都不再包含在默认错误页中。这降低了向客户泄露信息的风险。服务器。Error, include-message和server.error。Include-binding-errors可用于分别控制消息和绑定错误的包含。支持的值为always、on-param和neyen w