From 2976e1e20ef35775630a11f9fc7563ab5b6216f0 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期五, 30 十月 2026 19:12:29 +0800
Subject: [PATCH] fix(api): 修复全量接口测试发现的 500 系统异常
---
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
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 97a63a2..d8f1054 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
@@ -50,7 +50,7 @@
/**
* 鍏ㄥ眬寮傚父澶勭悊鍣紝灏� Exception 缈昏瘧鎴� CommonResult + 瀵瑰簲鐨勫紓甯哥紪鍙�
*
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
*/
@RestControllerAdvice
@AllArgsConstructor
@@ -114,6 +114,10 @@
}
if (ex instanceof AccessDeniedException) {
return accessDeniedExceptionHandler(request, (AccessDeniedException) ex);
+ }
+ // 鍙傛暟鏍¢獙绫诲紓甯革紙濡� Assert.notNull 鎶涘嚭鐨� IllegalArgumentException锛夊睘浜庡鎴风闂锛屼笉搴旀寜 500 澶勭悊
+ if (ex instanceof IllegalArgumentException) {
+ return illegalArgumentExceptionHandler((IllegalArgumentException) ex);
}
return defaultExceptionHandler(request, ex);
}
@@ -268,6 +272,18 @@
}
/**
+ * 澶勭悊鍙傛暟闈炴硶寮傚父
+ *
+ * 鏉ユ簮鏄紝涓氬姟浠g爜涓娇鐢� {@link Assert#notNull} 绛夋柇瑷�鏍¢獙鍏ュ弬锛屾垨缂撳瓨娉ㄨВ浣跨敤绌� key銆�
+ * 杩欑被闂灞炰簬璋冪敤鏂逛紶鍙備笉姝g‘锛岃繑鍥� 400 鑰屼笉鏄� 500锛岄伩鍏嶅墠绔妸鍙傛暟闂璇垽涓虹郴缁熸晠闅溿��
+ */
+ @ExceptionHandler(value = IllegalArgumentException.class)
+ public CommonResult<?> illegalArgumentExceptionHandler(IllegalArgumentException ex) {
+ log.warn("[illegalArgumentExceptionHandler]", ex);
+ return CommonResult.error(BAD_REQUEST.getCode(), ex.getMessage());
+ }
+
+ /**
* 澶勭悊 Spring Security 鏉冮檺涓嶈冻鐨勫紓甯�
*
* 鏉ユ簮鏄紝浣跨敤 @PreAuthorize 娉ㄨВ锛孉OP 杩涜鏉冮檺鎷︽埅
--
Gitblit v1.9.3