Commit d7411081c76149145b5b6996f16522a7aa7c892e

Authored by YunaiV
1 parent 809d6aaa

fix(web):修复 ServiceException 成功码导致全局异常处理失败

当 ServiceException 携带成功码 0 时,由 GlobalExceptionHandler 统一返回系统异常,
避免 CommonResult.error 再次抛出 IllegalArgumentException。

Refs #1196
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
@@ -313,6 +313,11 @@ public class GlobalExceptionHandler { @@ -313,6 +313,11 @@ public class GlobalExceptionHandler {
313 // 忽略日志,避免影响主流程 313 // 忽略日志,避免影响主流程
314 } 314 }
315 } 315 }
  316 + // ServiceException 的错误码可能为成功码,直接调用 CommonResult.error 会抛出异常,此处统一按系统异常处理。
  317 + // 详见 Issue #1196:https://github.com/YunaiV/ruoyi-vue-pro/issues/1196
  318 + if (CommonResult.isSuccess(ex.getCode())) {
  319 + return CommonResult.error(INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg());
  320 + }
316 return CommonResult.error(ex.getCode(), ex.getMessage()); 321 return CommonResult.error(ex.getCode(), ex.getMessage());
317 } 322 }
318 323