GlobalExceptionHandler

@RestControllerAdvice
@Order(value = 2147483646)
class GlobalExceptionHandler

全局异常处理器

统一处理控制器抛出的异常并返回标准化错误响应

Author

lishangbu

Since

2018/8/30

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
@ExceptionHandler(value = [MethodArgumentNotValidException::class, BindException::class])
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
fun handleBodyValidException(exception: Exception): ApiResult<Void>

处理请求体验证异常

Link copied to clipboard
@ExceptionHandler(value = [Exception::class])
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
fun handleGlobalException(exception: Exception): ApiResult<Void>

处理全局异常

Link copied to clipboard
@ExceptionHandler(value = [HttpMessageNotWritableException::class])
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
fun handleHttpMessageNotWritableException(exception: HttpMessageNotWritableException): ApiResult<Void>

处理HTTP 消息不可写异常

@ExceptionHandler(value = [HttpRequestMethodNotSupportedException::class])
@ResponseStatus(value = HttpStatus.METHOD_NOT_ALLOWED)
fun handleHttpRequestMethodNotSupportedException(exception: HttpRequestMethodNotSupportedException): ApiResult<Void>

处理HTTP 请求方法不支持异常

Link copied to clipboard
@ExceptionHandler(value = [IllegalArgumentException::class])
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
fun handleIllegalArgumentException(exception: IllegalArgumentException): ApiResult<Void>

处理非法参数异常

Link copied to clipboard
@ExceptionHandler(value = [IllegalStateException::class])
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
fun handleIllegalStateException(exception: IllegalStateException): ApiResult<Void>

处理非法状态异常

Link copied to clipboard
@ExceptionHandler(value = [NoResourceFoundException::class])
@ResponseStatus(value = HttpStatus.NOT_FOUND)
fun handleNoResourceFoundException(exception: NoResourceFoundException): ApiResult<Void>

处理资源不存在异常

Link copied to clipboard
@ExceptionHandler(value = [RuntimeException::class])
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
fun handleRuntimeException(exception: RuntimeException): ApiResult<Void>

处理运行时异常

Link copied to clipboard
@ExceptionHandler(value = [SQLException::class])
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
fun handleSQLException(exception: SQLException): ApiResult<Void>

处理SQL 异常

Link copied to clipboard
@ExceptionHandler(value = [UnsupportedOperationException::class])
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
fun handleUnsupportedOperationException(exception: UnsupportedOperationException): ApiResult<Void>

处理不支持操作异常