From 99e8ff82cc84f4ee231a8b4ec70a7ee2253f0bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E7=8E=89=E7=A5=A5?= Date: Mon, 3 Oct 2022 16:00:52 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=9B=B4=E6=96=B0=E3=80=91=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=E8=BF=94=E5=9B=9E=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/GlobalErrorAttributesHandler.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/snowy-web-app/src/main/java/vip/xiaonuo/core/handler/GlobalErrorAttributesHandler.java b/snowy-web-app/src/main/java/vip/xiaonuo/core/handler/GlobalErrorAttributesHandler.java index 79541989..d1b1117b 100644 --- a/snowy-web-app/src/main/java/vip/xiaonuo/core/handler/GlobalErrorAttributesHandler.java +++ b/snowy-web-app/src/main/java/vip/xiaonuo/core/handler/GlobalErrorAttributesHandler.java @@ -22,6 +22,7 @@ import org.springframework.stereotype.Component; import org.springframework.web.context.request.WebRequest; import vip.xiaonuo.common.exception.CommonException; import vip.xiaonuo.common.pojo.CommonResult; +import vip.xiaonuo.common.util.CommonServletUtil; import java.util.Map; @@ -43,9 +44,16 @@ public class GlobalErrorAttributesHandler extends DefaultErrorAttributes { if (ObjectUtil.isNotEmpty(status)) { // 如果其为404,则处理 if (HttpStatus.HTTP_NOT_FOUND == Convert.toInt(status)) { - return BeanUtil.beanToMap(CommonResult.get(HttpStatus.HTTP_NOT_FOUND, "路径不存在", null)); + Object path = defaultErrorAttributes.get("path"); + if(ObjectUtil.isNotEmpty(path)) { + return BeanUtil.beanToMap(CommonResult.get(HttpStatus.HTTP_NOT_FOUND, "路径不存在,请求地址:" + + Convert.toStr(path), null)); + } else { + return BeanUtil.beanToMap(CommonResult.get(HttpStatus.HTTP_NOT_FOUND, "路径不存在", null)); + } } else { - return BeanUtil.beanToMap(CommonResult.get(HttpStatus.HTTP_INTERNAL_ERROR, "服务器异常", null)); + return BeanUtil.beanToMap(CommonResult.get(HttpStatus.HTTP_INTERNAL_ERROR, "服务器异常,请求地址:" + + CommonServletUtil.getRequest().getRequestURL(), null)); } } @@ -56,11 +64,12 @@ public class GlobalErrorAttributesHandler extends DefaultErrorAttributes { CommonException commonException = (CommonException) throwable; return BeanUtil.beanToMap(CommonResult.error(commonException.getMsg())); } else { - return BeanUtil.beanToMap(CommonResult.get(HttpStatus.HTTP_INTERNAL_ERROR, "服务器异常", null)); + return BeanUtil.beanToMap(CommonResult.get(HttpStatus.HTTP_INTERNAL_ERROR, "服务器异常,请求地址:" + + CommonServletUtil.getRequest().getRequestURL(), null)); } } else { // throwable为空,则直接返回默认异常 - return BeanUtil.beanToMap(CommonResult.error("服务器异常")); + return BeanUtil.beanToMap(CommonResult.error("服务器异常,请求地址:" + CommonServletUtil.getRequest().getRequestURL())); } } }