fix(mcwl-framework): 处理Redis连接超时
parent
f94104bf55
commit
a503ef5112
|
@ -4,6 +4,8 @@ import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import io.lettuce.core.RedisCommandTimeoutException;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -28,6 +30,9 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
int code = HttpStatus.UNAUTHORIZED;
|
int code = HttpStatus.UNAUTHORIZED;
|
||||||
|
if (e.getCause() instanceof RedisCommandTimeoutException) {
|
||||||
|
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.warn("网络超时,请检查网络稍后重试")));
|
||||||
|
}
|
||||||
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
|
||||||
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
|
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,8 @@ public class GlobalExceptionHandler {
|
||||||
/**
|
/**
|
||||||
* redis连接超时异常
|
* redis连接超时异常
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(QueryTimeoutException.class)
|
@ExceptionHandler(org.springframework.dao.QueryTimeoutException.class)
|
||||||
public AjaxResult commandTimeoutException(QueryTimeoutException e, HttpServletRequest request) {
|
public AjaxResult commandTimeoutException(org.springframework.dao.QueryTimeoutException e, HttpServletRequest request) {
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
log.error("redis异常{},{}", requestURI, e.getMessage());
|
log.error("redis异常{},{}", requestURI, e.getMessage());
|
||||||
return AjaxResult.warn("超时");
|
return AjaxResult.warn("超时");
|
||||||
|
|
|
@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import com.mcwl.common.exception.ServiceException;
|
import com.mcwl.common.exception.ServiceException;
|
||||||
import io.lettuce.core.RedisCommandTimeoutException;
|
import io.lettuce.core.RedisCommandTimeoutException;
|
||||||
import io.lettuce.core.RedisException;
|
import io.lettuce.core.RedisException;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
Loading…
Reference in New Issue