更新登录超时的判断

pull/64/head
fengshuonan 2021-02-22 22:44:25 +08:00
parent a38d3126b6
commit 9322587fd9
1 changed files with 12 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.exception.enums.defaults.DefaultBusinessExceptionEnum;
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.ResponseRenderUtil;
import cn.stylefeng.roses.kernel.validator.exception.ParamValidateException;
import cn.stylefeng.roses.kernel.validator.exception.enums.ValidatorExceptionEnum;
@ -180,11 +181,12 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String authError(AuthException authException, HttpServletRequest request, HttpServletResponse response, Model model) {
String errorCode = authException.getErrorCode();
// 如果是会话过期或超时
if (AuthExceptionEnum.AUTH_EXPIRED_ERROR.getErrorCode().equals(errorCode)) {
// 如果是普通请求
if (request.getContentType() == null
|| request.getContentType().toLowerCase().contains("text/html")) {
if (HttpServletUtil.getNormalRequestFlag(request)) {
model.addAttribute("tips", AuthExceptionEnum.AUTH_EXPIRED_ERROR.getUserTip());
return "/login.html";
} else {
@ -196,6 +198,14 @@ 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";
}
}
// 默认响应前端json
ErrorResponseData errorResponseData = renderJson(authException.getErrorCode(), authException.getUserTip(), authException);
ResponseRenderUtil.renderJsonResponse(response, errorResponseData);