From 1a2dd7eb77140a62c12a3e102e9b4593f13ab741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Sat, 18 Apr 2020 18:29:49 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20=20=E5=B7=B2?= =?UTF-8?q?=E5=90=88=E5=B9=B6=20!52=20=E5=85=A8=E5=B1=80=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86validation=20Exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GlobalExceptionHandlerResolver.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/GlobalExceptionHandlerResolver.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/GlobalExceptionHandlerResolver.java index 185fff514..dbb8fe397 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/GlobalExceptionHandlerResolver.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/GlobalExceptionHandlerResolver.java @@ -75,11 +75,25 @@ public class GlobalExceptionHandlerResolver { * @param exception * @return R */ - @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class}) + @ExceptionHandler({MethodArgumentNotValidException.class}) @ResponseStatus(HttpStatus.BAD_REQUEST) public R handleBodyValidException(MethodArgumentNotValidException exception) { List fieldErrors = exception.getBindingResult().getFieldErrors(); - log.error("参数绑定异常,ex = {}", fieldErrors.get(0).getDefaultMessage()); + log.warn("参数绑定异常,ex = {}", fieldErrors.get(0).getDefaultMessage()); + return R.failed(fieldErrors.get(0).getDefaultMessage()); + } + + /** + * validation Exception (以form-data形式传参) + * + * @param exception + * @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()); } }