Commit c647aeb9 by guojuxing

全局异常修改

parent 333d12a1
package com.gic.enterprise.exception;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
......@@ -25,33 +22,12 @@ import com.gic.enterprise.error.ErrorCode;
*
* @author hua
*
*/
@ControllerAdvice
@ResponseBody
*/
public class GlobalExceptionHandler {
private static Logger logger = LogManager.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(Exception.class)
public RestResponse controllerException(HttpServletResponse response, Exception ex) {
logger.error("err", ex);
RestResponse failureResponse = getRestResponse(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMsg());
StringBuilder sb = new StringBuilder();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintWriter printWriter = new PrintWriter(baos)) {
logger.warn("e", ex);
}
try {
sb.append(baos.toString());
} catch (Exception ignored) {
}
if (sb.length() == 0) {
sb.append(ex.getMessage());
}
// 输出详细错误信息,便于调试
failureResponse.setDetailError(sb.toString());
return failureResponse;
}
/**
* 参数校验异常统一处理
* @param e
......
......@@ -88,8 +88,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
return true;
}
if (userDetail == null || userDetail.getUserInfo() == null) {
response.setStatus(6666);
response.sendError(6666, "登录信息不存在,请登录");
throw new CommonException(ErrorCode.LOGIN_INVALID.getErrorCode(), "登录信息不存在,请登录");
}
request.setAttribute("user", userDetail);
......@@ -111,8 +109,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
//判断是否有权限
Map<String, Object> menuUrlMap = userDetail.getMenuUrlMap();
if (menuUrlMap == null || menuUrlMap.isEmpty()) {
response.setStatus(0003);
response.sendError(0003, "sorry,您无该页面的访问权限,请联系超级管理员!");
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
......@@ -120,16 +116,12 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
//说明是操作项
//如果匹配上了,说明是没权限
if (menuUrlMap.containsKey(uri)) {
response.setStatus(0003);
response.sendError(0003, "sorry,您无该页面的访问权限,请联系超级管理员!");
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
} else {
//说明是页面
//如果没有匹配上,说明没权限
if (!menuUrlMap.containsKey(uri)) {
response.setStatus(0003);
response.sendError(0003, "sorry,您无该页面的访问权限,请联系超级管理员!");
throw new CommonException(ErrorCode.SYSTEM_ERROR.getErrorCode(), "sorry,您无该页面的访问权限,请联系超级管理员!");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment