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;