| | |
| | | import jakarta.validation.ConstraintViolationException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dromara.common.core.domain.R; |
| | | import org.dromara.common.core.exception.DemoModeException; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.exception.base.BaseException; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; |
| | | import org.springframework.web.servlet.NoHandlerFoundException; |
| | | |
| | | /** |
| | | * 全局异常处理器 |
| | |
| | | HttpServletRequest request) { |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod()); |
| | | return R.fail(e.getMessage()); |
| | | return R.fail(HttpStatus.HTTP_BAD_METHOD, e.getMessage()); |
| | | } |
| | | |
| | | /** |
| | |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI); |
| | | return R.fail(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue())); |
| | | } |
| | | |
| | | /** |
| | | * 找不到路由 |
| | | */ |
| | | @ExceptionHandler(NoHandlerFoundException.class) |
| | | public R<Void> handleNoHandlerFoundException(NoHandlerFoundException e, HttpServletRequest request) { |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请求地址'{}'不存在.", requestURI); |
| | | return R.fail(HttpStatus.HTTP_NOT_FOUND, e.getMessage()); |
| | | } |
| | | |
| | | /** |
| | |
| | | return R.fail(message); |
| | | } |
| | | |
| | | /** |
| | | * 演示模式异常 |
| | | */ |
| | | @ExceptionHandler(DemoModeException.class) |
| | | public R<Void> handleDemoModeException(DemoModeException e) { |
| | | return R.fail("演示模式,不允许操作"); |
| | | } |
| | | } |