Spring-boot自定义异常message返回为空问题

我的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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值