Commit c8075f38 by 丁伟峰

for test

1 parent 82734f7d
...@@ -24,30 +24,37 @@ public class GlobalExceptionHandler { ...@@ -24,30 +24,37 @@ public class GlobalExceptionHandler {
//处理 form data方式调用接口校验失败抛出的异常 //处理 form data方式调用接口校验失败抛出的异常
@ExceptionHandler(BindException.class) @ExceptionHandler(BindException.class)
public Result<?> bindExceptionHandler(BindException e) { public Result<?> bindExceptionHandler(BindException e) {
log.error("!!!!!!!!!!!! bindExceptionHandler !!!!!!!!!!!!!!");
List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors(); List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors();
List<String> collect = fieldErrors.stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.toList()); List<String> collect = fieldErrors.stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.toList());
log.error(String.join(";", collect));
return Result.failed(String.join(";", collect)); return Result.failed(String.join(";", collect));
} }
// 处理 json 请求体调用接口校验失败抛出的异常 // 处理 json 请求体调用接口校验失败抛出的异常
@ExceptionHandler(MethodArgumentNotValidException.class) @ExceptionHandler(MethodArgumentNotValidException.class)
public Result<?> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) { public Result<?> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
log.error("!!!!!!!!!!!! methodArgumentNotValidExceptionHandler !!!!!!!!!!!!!!");
List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors(); List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors();
List<String> collect = fieldErrors.stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.toList()); List<String> collect = fieldErrors.stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.toList());
log.error(String.join(";", collect));
return Result.failed(String.join(";", collect)); return Result.failed(String.join(";", collect));
} }
// 处理单个参数校验失败抛出的异常 // 处理单个参数校验失败抛出的异常
@ExceptionHandler(ConstraintViolationException.class) @ExceptionHandler(ConstraintViolationException.class)
public Result<?> constraintViolationExceptionHandler(ConstraintViolationException e) { public Result<?> constraintViolationExceptionHandler(ConstraintViolationException e) {
log.error("!!!!!!!!!!!! constraintViolationExceptionHandler !!!!!!!!!!!!!!");
Set<ConstraintViolation<?>> constraintViolations = e.getConstraintViolations(); Set<ConstraintViolation<?>> constraintViolations = e.getConstraintViolations();
List<String> collect = constraintViolations.stream().map(ConstraintViolation::getMessage).collect(Collectors.toList()); List<String> collect = constraintViolations.stream().map(ConstraintViolation::getMessage).collect(Collectors.toList());
log.error(String.join(";", collect));
return Result.failed(String.join(";", collect)); return Result.failed(String.join(";", collect));
} }
// 处理以上处理不了的其他异常 // 处理以上处理不了的其他异常
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public Result<?> exceptionHandler(Exception e) { public Result<?> exceptionHandler(Exception e) {
log.error("!!!!!!!!!!!! exceptionHandler !!!!!!!!!!!!!!");
log.error("$$$$$$$$$$$$$$$$$$$$$$$$$" + e.toString()); log.error("$$$$$$$$$$$$$$$$$$$$$$$$$" + e.toString());
return Result.failed(e.toString()); return Result.failed(e.toString());
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!