fix:【framework 全局】GlobalExceptionHandler 处理 guava UncheckedExecutionException 异常,https://t.zsxq.com/UszdH

pull/150/MERGE
YunaiV 2025-08-03 19:39:33 +08:00
parent 9502fef140
commit a277987139
3 changed files with 31 additions and 1 deletions

View File

@ -61,7 +61,13 @@
<optional>true</optional>
</dependency>
<!-- xss -->
<!-- 工具类相关 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>provided</scope> <!-- 设置为 provided只有工具类需要使用到 -->
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>

View File

@ -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
*
* <a href="https://t.zsxq.com/UszdH">https://t.zsxq.com/UszdH</a>
*/
@ExceptionHandler(value = UncheckedExecutionException.class)
public CommonResult<?> uncheckedExecutionExceptionHandler(HttpServletRequest req, UncheckedExecutionException ex) {
return allExceptionHandler(req, ex.getCause());
}
/**
* ServiceException
*

View File

@ -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}}