mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-11 05:19:00 +08:00
🐛 Fixing a bug. 已合并 !52 全局异常处理validation Exception
This commit is contained in:
1 parent
0d343fed34
commit
1a2dd7eb77
1 file changed
+16
-2
+16
-2
@@ -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<FieldError> 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<FieldError> fieldErrors = exception.getBindingResult().getFieldErrors();
|
||||
log.warn("参数绑定异常,ex = {}", fieldErrors.get(0).getDefaultMessage());
|
||||
return R.failed(fieldErrors.get(0).getDefaultMessage());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user