From c636e6909b8ed1dc1dba18bceca2554d5adde7f9 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期五, 21 一月 2022 18:29:44 +0800 Subject: [PATCH] Merge remote-tracking branch 'ruoyi-vue/master' into dev --- ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java index d0f00c6..bc58049 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java @@ -3,12 +3,14 @@ import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.exception.NotPermissionException; import cn.dev33.satoken.exception.NotRoleException; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.HttpStatus; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.exception.DemoModeException; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.StringUtils; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.validation.BindException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -16,7 +18,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import javax.servlet.http.HttpServletRequest; +import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; +import java.util.stream.Collectors; /** * 鍏ㄥ眬寮傚父澶勭悊鍣� @@ -62,7 +66,7 @@ */ @ExceptionHandler(HttpRequestMethodNotSupportedException.class) public AjaxResult<Void> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, - HttpServletRequest request) { + HttpServletRequest request) { String requestURI = request.getRequestURI(); log.error("璇锋眰鍦板潃'{}',涓嶆敮鎸�'{}'璇锋眰", requestURI, e.getMethod()); return AjaxResult.error(e.getMessage()); @@ -75,7 +79,7 @@ public AjaxResult<Void> handleServiceException(ServiceException e, HttpServletRequest request) { log.error(e.getMessage(), e); Integer code = e.getCode(); - return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage()); + return ObjectUtil.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage()); } /** @@ -104,7 +108,9 @@ @ExceptionHandler(BindException.class) public AjaxResult<Void> handleBindException(BindException e) { log.error(e.getMessage(), e); - String message = e.getAllErrors().get(0).getDefaultMessage(); + String message = e.getAllErrors().stream() + .map(DefaultMessageSourceResolvable::getDefaultMessage) + .collect(Collectors.joining(", ")); return AjaxResult.error(message); } @@ -114,7 +120,9 @@ @ExceptionHandler(ConstraintViolationException.class) public AjaxResult<Void> constraintViolationException(ConstraintViolationException e) { log.error(e.getMessage(), e); - String message = e.getConstraintViolations().iterator().next().getMessage(); + String message = e.getConstraintViolations().stream() + .map(ConstraintViolation::getMessage) + .collect(Collectors.joining(", ")); return AjaxResult.error(message); } -- Gitblit v1.9.3