From ca497f8389174bb81e91f840cab70c9579bcdd29 Mon Sep 17 00:00:00 2001 From: 18582019636 <1657978663@qq.com> Date: 星期二, 25 六月 2024 18:17:01 +0800 Subject: [PATCH] feat: 代码初始化 --- ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java index bbaef82..8c641b5 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java @@ -13,6 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.validation.BindException; +import org.springframework.validation.FieldError; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingPathVariableException; @@ -122,16 +123,6 @@ } /** - * 自定义验证异常 - */ - @ExceptionHandler(MethodArgumentNotValidException.class) - public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { - log.error(e.getMessage(), e); - String message = e.getBindingResult().getFieldError().getDefaultMessage(); - return AjaxResult.error(message); - } - - /** * 内部认证异常 */ @ExceptionHandler(InnerAuthException.class) @@ -148,11 +139,24 @@ } /** - * 演示模式异常 + * 自定义异常 */ @ExceptionHandler(GlobalException.class) public R<String> handleDemoModeException(GlobalException g) { - return R.fail(g.getDetailMessage()); + return R.fail(g.getMessage()); + } + + /** + * 捕获jsr303参数校验异常 + * + * @author hjl + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + public R<String> methodArgumentNotValidExceptionExceptionException(MethodArgumentNotValidException e) { + FieldError fieldError = e.getBindingResult().getFieldError(); + assert fieldError != null; + String defaultMessage = fieldError.getDefaultMessage(); + return R.fail(defaultMessage); } } -- Gitblit v1.7.1