From a277987139b55e5cabce96bf8ef73cb45299e507 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Aug 2025 19:39:33 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E3=80=90framework=20=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E3=80=91GlobalExceptionHandler=20=E5=A4=84=E7=90=86?= =?UTF-8?q?=20guava=20UncheckedExecutionException=20=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=EF=BC=8Chttps://t.zsxq.com/UszdH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao-spring-boot-starter-web/pom.xml | 8 +++++++- .../web/core/handler/GlobalExceptionHandler.java | 14 ++++++++++++++ .../controller/admin/auth/AuthController.http | 10 ++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/yudao-framework/yudao-spring-boot-starter-web/pom.xml b/yudao-framework/yudao-spring-boot-starter-web/pom.xml index ac1ab3dfc..0943f9f5a 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-web/pom.xml @@ -61,7 +61,13 @@ true - + + + com.google.guava + guava + provided + + org.jsoup jsoup diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java index 627a5ea78..abab1ce51 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java @@ -17,6 +17,7 @@ import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import com.fasterxml.jackson.databind.exc.InvalidFormatException; +import com.google.common.util.concurrent.UncheckedExecutionException; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.ConstraintViolation; import jakarta.validation.ConstraintViolationException; @@ -111,6 +112,9 @@ public class GlobalExceptionHandler { if (ex instanceof AccessDeniedException) { return accessDeniedExceptionHandler(request, (AccessDeniedException) ex); } + if (ex instanceof UncheckedExecutionException && ex.getCause() != ex) { + return allExceptionHandler(request, ex.getCause()); + } return defaultExceptionHandler(request, ex); } @@ -266,6 +270,16 @@ public class GlobalExceptionHandler { return CommonResult.error(FORBIDDEN); } + /** + * 处理 Guava UncheckedExecutionException + * + * 例如说,缓存加载报错,可见 https://t.zsxq.com/UszdH + */ + @ExceptionHandler(value = UncheckedExecutionException.class) + public CommonResult uncheckedExecutionExceptionHandler(HttpServletRequest req, UncheckedExecutionException ex) { + return allExceptionHandler(req, ex.getCause()); + } + /** * 处理业务异常 ServiceException * diff --git a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.http b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.http index f42dfcd03..f21eb5268 100644 --- a/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.http +++ b/yudao-module-system/yudao-module-system-server/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.http @@ -21,6 +21,16 @@ tenant-id: {{adminTenantId}} "password": "admin123" } +### 请求 /login 接口 => 失败(租户不存在) +POST {{baseUrl}}/system/auth/login +Content-Type: application/json +tenant-id: 2 + +{ + "username": "admin", + "password": "admin123" +} + ### 请求 /get-permission-info 接口 => 成功 GET {{baseUrl}}/system/auth/get-permission-info Authorization: Bearer {{token}}