| | |
| | | |
| | | import com.example.jz.exception.BusinessException; |
| | | import com.example.jz.modle.R; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.validation.BindException; |
| | | import org.springframework.web.bind.MethodArgumentNotValidException; |
| | |
| | | @RestControllerAdvice |
| | | public class DefaultExceptionHandlerConfig { |
| | | |
| | | |
| | | @ExceptionHandler(BindException.class) |
| | | public R<String> bindExceptionHandler(BindException e) { |
| | | e.printStackTrace(); |
| | | return R.failed(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage()); |
| | | |
| | | } |
| | | |
| | | @ExceptionHandler(MethodArgumentNotValidException.class) |
| | | public R<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) { |
| | | e.printStackTrace(); |
| | | return R.failed(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage()); |
| | | } |
| | | |
| | | @ExceptionHandler(BusinessException.class) |
| | | public R<String> unauthorizedExceptionHandler(BusinessException e) { |
| | | e.printStackTrace(); |
| | | return R.failed(e.getMessage()); |
| | | } |
| | | |
| | | @ExceptionHandler(Exception.class) |
| | | public R<String> ExceptionHandler(Exception e) { |
| | | e.printStackTrace(); |
| | | return R.failed(e.getMessage()); |
| | | } |
| | | } |