Class GlobalExceptionHandler

java.lang.Object
io.github.xezzon.zeroweb.common.exception.GlobalExceptionHandler
Direct Known Subclasses:
AdminExceptionHandler, OpenExceptionHandler

@RestControllerAdvice public class GlobalExceptionHandler extends Object
全局异常处理 错误码: 依据`异常类-错误码`映射查找。 HTTP 状态码: 客户端错误返回40x,服务端错误返回500。 异常名称: 异常类的简写名。 异常消息: 客户端异常的异常消息由错误码国际化(语言由 HTTP 请求头定义)得到。服务端异常则返回统一的消息,以便向客户端隐藏细节。 日志:通常的异常日志级别为 WARN,部分异常可视情况提高或降低日志级别。日志的异常消息取自 Throwable.getMessage(),自行实现的异常会依据异常类名对内容进行国际化。
Author:
xezzon
  • Field Details

  • Constructor Details

    • GlobalExceptionHandler

      public GlobalExceptionHandler()
  • Method Details

    • handleException

      @ExceptionHandler(ZerowebBusinessException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleException(ZerowebBusinessException e, jakarta.servlet.http.HttpServletRequest request)
      业务异常
    • handleException

      @ExceptionHandler(java.lang.Throwable.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleException(Throwable e, jakarta.servlet.http.HttpServletRequest request)
      非业务异常(通用)
    • handleException

      @ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleException(org.springframework.web.bind.MethodArgumentNotValidException e, jakarta.servlet.http.HttpServletRequest request)
      参数校验不通过
    • handleException

      @ExceptionHandler(org.springframework.web.servlet.resource.NoResourceFoundException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleException(org.springframework.web.servlet.resource.NoResourceFoundException e, jakarta.servlet.http.HttpServletRequest request)
      请求资源不存在
    • handleException

      @ExceptionHandler(cn.dev33.satoken.exception.NotLoginException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleException(cn.dev33.satoken.exception.NotLoginException e, jakarta.servlet.http.HttpServletRequest request)
      未登录