【7.0.4】修复异常拦截

pull/73/head
fengshuonan 2021-05-18 10:56:47 +08:00
parent 3f9ec43b8c
commit fabf9a8373
1 changed files with 28 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import cn.stylefeng.roses.kernel.rule.exception.enums.defaults.DefaultBusinessEx
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
import cn.stylefeng.roses.kernel.rule.util.ExceptionUtil;
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
import cn.stylefeng.roses.kernel.rule.util.ProjectUtil;
import cn.stylefeng.roses.kernel.rule.util.ResponseRenderUtil;
import cn.stylefeng.roses.kernel.validator.api.exception.ParamValidateException;
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
@ -187,8 +188,8 @@ public class GlobalExceptionHandler {
// 如果是普通请求
if (HttpServletUtil.getNormalRequestFlag(request)) {
model.addAttribute("tips", AuthExceptionEnum.AUTH_EXPIRED_ERROR.getUserTip());
return "/login.html";
// 根据是否是前后端分离项目,进行结果响应
return this.renderLoginResult(response, authException, model);
} else {
// 其他请求或者是ajax请求
response.setHeader("Guns-Session-Timeout", "true");
@ -201,8 +202,8 @@ public class GlobalExceptionHandler {
// 如果是没带token访问页面则返回到登录界面
if (AuthExceptionEnum.TOKEN_GET_ERROR.getErrorCode().equals(errorCode)) {
if (HttpServletUtil.getNormalRequestFlag(request)) {
model.addAttribute("tips", AuthExceptionEnum.AUTH_EXPIRED_ERROR.getUserTip());
return "/login.html";
// 根据是否是前后端分离项目,进行结果响应
return this.renderLoginResult(response, authException, model);
}
}
@ -322,4 +323,27 @@ public class GlobalExceptionHandler {
return StrUtil.removePrefix(stringBuilder.toString(), SymbolConstant.COMMA);
}
/**
*
* <p>
*
* <p>
* Json
*
* @author fengshuonan
* @date 2021/5/18 10:48
*/
private String renderLoginResult(HttpServletResponse response, AuthException authException, Model model) {
if (ProjectUtil.getSeparationFlag()) {
response.setHeader("Guns-Session-Timeout", "true");
ErrorResponseData errorResponseData = renderJson(authException.getErrorCode(), authException.getUserTip(), authException);
ResponseRenderUtil.renderJsonResponse(response, errorResponseData);
return null;
}
model.addAttribute("tips", authException.getUserTip());
return "/login.html";
}
}