liu
10 天以前 2976e1e20ef35775630a11f9fc7563ab5b6216f0
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
@@ -115,6 +115,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 @@
    }
    /**
     * 处理参数非法异常
     *
     * 来源是,业务代码中使用 {@link Assert#notNull} 等断言校验入参,或缓存注解使用空 key。
     * 这类问题属于调用方传参不正确,返回 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 注解,AOP 进行权限拦截