| | |
| | | import org.springframework.data.redis.connection.PoolException; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.web.HttpRequestMethodNotSupportedException; |
| | | 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.servlet.NoHandlerFoundException; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 异常处理器 |
| | |
| | | public class JeecgBootExceptionHandler { |
| | | |
| | | /** |
| | | * @Valid 抛出异常处理 |
| | | * @param |
| | | * @return |
| | | */ |
| | | @ExceptionHandler(MethodArgumentNotValidException.class) |
| | | public Result<?> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex){ |
| | | Map<String, Object> errors = new HashMap<>(); |
| | | ex.getBindingResult().getFieldErrors().forEach(error -> { |
| | | errors.put(error.getField(), error.getDefaultMessage()); |
| | | }); |
| | | log.error(ex.getMessage(), ex); |
| | | return Result.error(errors.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 处理自定义异常 |
| | | */ |
| | | @ExceptionHandler(JeecgBootException.class) |