From 086be8e55ba4590e1d863172397a474c97275cbd Mon Sep 17 00:00:00 2001 From: pig666 Date: Sat, 24 Oct 2020 16:15:01 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20#1957=20Spring=20Bo?= =?UTF-8?q?ot=20=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=20/error=20=E5=AF=BC?= =?UTF-8?q?=E8=87=B4OAuth=202.0=20NPE=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handle/GlobalBizExceptionHandler.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 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 bb789b4a4..3b918f3d1 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 @@ -24,12 +24,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.http.HttpStatus; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.core.SpringSecurityMessageSource; -import org.springframework.validation.BindException; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -42,6 +39,7 @@ import java.util.List; * @date 2020-06-29 */ @Slf4j +@RestController @RestControllerAdvice @ConditionalOnExpression("!'${security.oauth2.client.clientId}'.isEmpty()") public class GlobalBizExceptionHandler { @@ -89,16 +87,12 @@ public class GlobalBizExceptionHandler { } /** - * validation Exception (以form-data形式传参) - * @param exception + * 避免 404 重定向到 /error 导致NPE ,ignore-url 需要配置对应端点 * @return R */ - @ExceptionHandler({ BindException.class }) - @ResponseStatus(HttpStatus.BAD_REQUEST) - public R bindExceptionHandler(BindException exception) { - List fieldErrors = exception.getBindingResult().getFieldErrors(); - log.warn("参数绑定异常,ex = {}", fieldErrors.get(0).getDefaultMessage()); - return R.failed(fieldErrors.get(0).getDefaultMessage()); + @DeleteMapping("/error") + @ResponseStatus(HttpStatus.NOT_FOUND) + public R noHandlerFoundException() { + return R.failed(); } - }