From 5609608e090b3f0ae0745e3bbd0d451fbb5de891 Mon Sep 17 00:00:00 2001 From: MicLng Date: Wed, 27 Oct 2021 11:14:45 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20close=20#3264=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=97=A0=E6=B3=95=E8=AE=B0=E5=BD=95=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=A0=A1=E9=AA=8C=E7=9A=84=E5=BC=82=E5=B8=B8=E5=8F=8A?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E8=87=AA=E5=AE=9A=E4=B9=89=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/sentinel/handle/GlobalBizExceptionHandler.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/handle/GlobalBizExceptionHandler.java b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/handle/GlobalBizExceptionHandler.java index 58afae181..ac744251c 100644 --- a/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/handle/GlobalBizExceptionHandler.java +++ b/pigx-common/pigx-common-sentinel/src/main/java/com/pig4cloud/pigx/common/sentinel/handle/GlobalBizExceptionHandler.java @@ -23,8 +23,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.http.HttpStatus; import org.springframework.security.access.AccessDeniedException; +import org.springframework.validation.BindException; import org.springframework.validation.FieldError; -import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -75,11 +75,11 @@ public class GlobalBizExceptionHandler { * @param exception * @return R */ - @ExceptionHandler({ MethodArgumentNotValidException.class }) + @ExceptionHandler({ BindException.class }) @ResponseStatus(HttpStatus.BAD_REQUEST) - public R handleBodyValidException(MethodArgumentNotValidException exception) { + public R handleBodyValidException(BindException exception) { List fieldErrors = exception.getBindingResult().getFieldErrors(); - log.warn("参数绑定异常,ex = {}", fieldErrors.get(0).getDefaultMessage()); + // 插入log 的逻辑 return R.failed(fieldErrors.get(0).getDefaultMessage()); }