From f6a7303fbaeee922e7257df0f7e5bd7456cd1345 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 10 Oct 2023 16:06:11 +0800 Subject: [PATCH] Add token has expired exception handler --- src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt index c4abedb..e4b41e0 100644 --- a/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt +++ b/src/main/kotlin/top/fatweb/api/handler/ExceptionHandler.kt @@ -2,6 +2,7 @@ package top.fatweb.api.handler import com.auth0.jwt.exceptions.JWTDecodeException import com.auth0.jwt.exceptions.SignatureVerificationException +import com.auth0.jwt.exceptions.TokenExpiredException import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.http.converter.HttpMessageNotReadableException @@ -32,6 +33,11 @@ class ExceptionHandler { ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage.split(":")[0], null) } + is TokenExpiredException -> { + log.debug(e.localizedMessage, e) + ResponseResult.fail(ResponseCode.SYSTEM_TOKEN_HAS_EXPIRED, e.localizedMessage, null) + } + is MethodArgumentNotValidException -> { log.debug(e.localizedMessage, e) val errorMessage = e.allErrors.map { error -> error.defaultMessage }.joinToString(". ")