From 1477ed0ac92c5af5f774cf78e27389850410720b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E7=8E=89=E7=A5=A5?= Date: Thu, 11 May 2023 23:14:25 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=9B=B4=E6=96=B0=E3=80=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=85=A8=E5=B1=80=E5=BC=82=E5=B8=B8=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=99=A8=E7=9A=84=E9=80=BB=E8=BE=91=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/GlobalErrorViewController.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/snowy-web-app/src/main/java/vip/xiaonuo/core/handler/GlobalErrorViewController.java b/snowy-web-app/src/main/java/vip/xiaonuo/core/handler/GlobalErrorViewController.java index 4d6b42e0..f0065db0 100644 --- a/snowy-web-app/src/main/java/vip/xiaonuo/core/handler/GlobalErrorViewController.java +++ b/snowy-web-app/src/main/java/vip/xiaonuo/core/handler/GlobalErrorViewController.java @@ -18,6 +18,7 @@ import cn.hutool.json.JSONUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import vip.xiaonuo.common.exception.CommonException; import vip.xiaonuo.common.pojo.CommonResult; import javax.servlet.http.HttpServletRequest; @@ -43,19 +44,22 @@ public class GlobalErrorViewController { CommonResult commonResult = new CommonResult<>(404, "路径不存在", null); Object model = request.getAttribute("model"); if(ObjectUtil.isNotEmpty(model)) { - JSONObject errorObj = JSONUtil.parseObj(model); - Integer code = errorObj.getInt("code"); - String msg = errorObj.getStr("msg"); - if(ObjectUtil.isAllNotEmpty(code, msg)) { - commonResult.setCode(code).setMsg(msg); - } else if(ObjectUtil.isNotEmpty(msg)) { - commonResult = CommonResult.error(msg); - } else { - commonResult = CommonResult.error(); - } if(model instanceof Exception){ - Exception e = (Exception) model; - log.error(">>> 服务器未知异常,具体信息:", e); + if(model instanceof CommonException) { + JSONObject errorObj = JSONUtil.parseObj(model); + Integer code = errorObj.getInt("code"); + String msg = errorObj.getStr("msg"); + if(ObjectUtil.isAllNotEmpty(code, msg)) { + commonResult.setCode(code).setMsg(msg); + } else if(ObjectUtil.isNotEmpty(msg)) { + commonResult = CommonResult.error(msg); + } else { + commonResult = CommonResult.error(); + } + } else { + commonResult = CommonResult.error(); + log.error(">>> 服务器未知异常,具体信息:", (Exception) model); + } } } return commonResult;