From a503ef51126f3157af523d2afac92820a73f4f9e Mon Sep 17 00:00:00 2001 From: yang <2119157836@qq.com> Date: Wed, 12 Mar 2025 11:27:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(mcwl-framework):=20=E5=A4=84=E7=90=86Redis?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/handle/AuthenticationEntryPointImpl.java | 5 +++++ .../mcwl/framework/web/exception/GlobalExceptionHandler.java | 4 ++-- .../java/com/mcwl/framework/web/service/TokenService.java | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mcwl-framework/src/main/java/com/mcwl/framework/security/handle/AuthenticationEntryPointImpl.java b/mcwl-framework/src/main/java/com/mcwl/framework/security/handle/AuthenticationEntryPointImpl.java index a58140e..6a9a4ca 100644 --- a/mcwl-framework/src/main/java/com/mcwl/framework/security/handle/AuthenticationEntryPointImpl.java +++ b/mcwl-framework/src/main/java/com/mcwl/framework/security/handle/AuthenticationEntryPointImpl.java @@ -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))); } diff --git a/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java b/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java index 8d14f8e..370fa5f 100644 --- a/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java +++ b/mcwl-framework/src/main/java/com/mcwl/framework/web/exception/GlobalExceptionHandler.java @@ -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("超时"); diff --git a/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java b/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java index 413d2fa..15c210e 100644 --- a/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java +++ b/mcwl-framework/src/main/java/com/mcwl/framework/web/service/TokenService.java @@ -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;