Add token has expired exception handler

This commit is contained in:
2023-10-10 16:06:11 +08:00
parent 2b905c09ae
commit f6a7303fba

View File

@@ -2,6 +2,7 @@ package top.fatweb.api.handler
import com.auth0.jwt.exceptions.JWTDecodeException import com.auth0.jwt.exceptions.JWTDecodeException
import com.auth0.jwt.exceptions.SignatureVerificationException import com.auth0.jwt.exceptions.SignatureVerificationException
import com.auth0.jwt.exceptions.TokenExpiredException
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.http.converter.HttpMessageNotReadableException import org.springframework.http.converter.HttpMessageNotReadableException
@@ -32,6 +33,11 @@ class ExceptionHandler {
ResponseResult.fail(ResponseCode.SYSTEM_REQUEST_ILLEGAL, e.localizedMessage.split(":")[0], null) 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 -> { is MethodArgumentNotValidException -> {
log.debug(e.localizedMessage, e) log.debug(e.localizedMessage, e)
val errorMessage = e.allErrors.map { error -> error.defaultMessage }.joinToString(". ") val errorMessage = e.allErrors.map { error -> error.defaultMessage }.joinToString(". ")