fix(mcwl-framework): 处理Redis连接超时

master
yang 2025-03-12 11:27:03 +08:00
parent f94104bf55
commit a503ef5112
3 changed files with 8 additions and 2 deletions

View File

@ -4,6 +4,8 @@ import java.io.IOException;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import io.lettuce.core.RedisCommandTimeoutException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
@ -28,6 +30,9 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
throws IOException
{
int code = HttpStatus.UNAUTHORIZED;
if (e.getCause() instanceof RedisCommandTimeoutException) {
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.warn("网络超时,请检查网络稍后重试")));
}
String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
}

View File

@ -49,8 +49,8 @@ public class GlobalExceptionHandler {
/**
* redis
*/
@ExceptionHandler(QueryTimeoutException.class)
public AjaxResult commandTimeoutException(QueryTimeoutException e, HttpServletRequest request) {
@ExceptionHandler(org.springframework.dao.QueryTimeoutException.class)
public AjaxResult commandTimeoutException(org.springframework.dao.QueryTimeoutException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("redis异常{},{}", requestURI, e.getMessage());
return AjaxResult.warn("超时");

View File

@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest;
import com.mcwl.common.exception.ServiceException;
import io.lettuce.core.RedisCommandTimeoutException;
import io.lettuce.core.RedisException;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;