【更新】优化全局异常处理,服务器未知异常定位更清晰

pull/120/head
xuyuxiang 2023-05-11 09:50:48 +08:00
parent 3c31705d76
commit 738ca7802e
3 changed files with 5 additions and 5 deletions

View File

@ -58,7 +58,7 @@ public class AuthExceptionUtil {
commonResult = CommonResult.error(saTokenException.getMessage()); commonResult = CommonResult.error(saTokenException.getMessage());
} else { } else {
// 未知异常才打印 // 未知异常才打印
log.error(">>> 服务器未知异常{},请求地址:{}", e.getMessage(), SaHolder.getRequest().getUrl()); log.error(">>> 服务器未知异常,请求地址:{},具体信息:", CommonServletUtil.getRequest().getRequestURL(), e);
// 未知异常返回服务器异常此处不可能执行进入因为本方法处理的一定是SaToken的异常此处仅为安全性考虑 // 未知异常返回服务器异常此处不可能执行进入因为本方法处理的一定是SaToken的异常此处仅为安全性考虑
commonResult = CommonResult.error("服务器异常"); commonResult = CommonResult.error("服务器异常");
} }

View File

@ -54,8 +54,8 @@ public class GlobalErrorViewController {
commonResult = CommonResult.error(); commonResult = CommonResult.error();
} }
if(model instanceof Exception){ if(model instanceof Exception){
Exception exception = (Exception) model; Exception e = (Exception) model;
log.error(">>> 服务器未知异常", exception); log.error(">>> 服务器未知异常,具体信息", e);
} }
} }
return commonResult; return commonResult;

View File

@ -107,7 +107,7 @@ public class GlobalExceptionUtil {
//文件上传错误特殊提示 //文件上传错误特殊提示
commonResult = CommonResult.error("请使用multipart/form-data方式上传文件"); commonResult = CommonResult.error("请使用multipart/form-data方式上传文件");
} else if (e instanceof MissingServletRequestPartException) { } else if (e instanceof MissingServletRequestPartException) {
log.error(">>> 文件上传参数异常:", e);
//文件上传错误特殊提示 //文件上传错误特殊提示
commonResult = CommonResult.error("请选择要上传的文件并检查文件参数名称是否正确"); commonResult = CommonResult.error("请选择要上传的文件并检查文件参数名称是否正确");
} else if (e instanceof SaTokenException) { } else if (e instanceof SaTokenException) {
@ -138,7 +138,7 @@ public class GlobalExceptionUtil {
commonResult = CommonResult.get(commonException.getCode(), commonException.getMsg(), null); commonResult = CommonResult.get(commonException.getCode(), commonException.getMsg(), null);
} else { } else {
// 未知异常打印详情 // 未知异常打印详情
log.error(">>> 服务器未知异常{}, 请求地址:{}", e, CommonServletUtil.getRequest().getRequestURL()); log.error(">>> 服务器未知异常,请求地址:{},具体信息:", CommonServletUtil.getRequest().getRequestURL(), e);
// 未知异常返回服务器异常 // 未知异常返回服务器异常
commonResult = CommonResult.error("服务器异常"); commonResult = CommonResult.error("服务器异常");
} }