diff --git a/src/docs/asciidoc/exception-api.adoc b/src/docs/asciidoc/exception-api.adoc index ea9356dc..13b49cd8 100644 --- a/src/docs/asciidoc/exception-api.adoc +++ b/src/docs/asciidoc/exception-api.adoc @@ -187,8 +187,11 @@ |`+ACCESS_TOKEN_NOT_EXIST+` |엑세스 토큰이 없습니다 -|`+EXPIRED_TOKEN+` -|토큰이 만료되었습니다 +|`+EXPIRED_ACCESS_TOKEN+` +|엑세스 토큰이 만료되었습니다 + +|`+EXPIRED_REFRESH_TOKEN+` +|리프레시 토큰이 만료되었습니다 |`+INVALID_ACCESS_TOKEN+` |유효하지 않은 엑세스 토큰입니다 diff --git a/src/main/java/com/spaceclub/global/exception/GlobalExceptionCode.java b/src/main/java/com/spaceclub/global/exception/GlobalExceptionCode.java index 2f160763..7ad3025f 100644 --- a/src/main/java/com/spaceclub/global/exception/GlobalExceptionCode.java +++ b/src/main/java/com/spaceclub/global/exception/GlobalExceptionCode.java @@ -11,7 +11,8 @@ public enum GlobalExceptionCode implements ExceptionMessageInterface { FAIL_DESERIALIZE("JSON 데이터를 변환하는데 실패했습니다"), INVALID_TOKEN_FORMAT("토큰 포멧이 잘못되었습니다"), // Bearer 포함 x ACCESS_TOKEN_NOT_EXIST("엑세스 토큰이 없습니다."), - EXPIRED_TOKEN("토큰이 만료되었습니다"), + EXPIRED_ACCESS_TOKEN("엑세스 토큰이 만료되었습니다"), + EXPIRED_REFRESH_TOKEN("리프레시 토큰이 만료되었습니다"), INVALID_ACCESS_TOKEN("유효하지 않은 엑세스 토큰입니다"), INVALID_REFRESH_TOKEN("유효하지 않은 리프레시 토큰입니다"), INVALID_FILE_EXTENSION("유효한 파일 확장자가 아닙니다"), diff --git a/src/main/java/com/spaceclub/global/jwt/Jwt.java b/src/main/java/com/spaceclub/global/jwt/Jwt.java index 4d854471..c6b3fc68 100644 --- a/src/main/java/com/spaceclub/global/jwt/Jwt.java +++ b/src/main/java/com/spaceclub/global/jwt/Jwt.java @@ -11,7 +11,7 @@ import java.util.Date; -import static com.spaceclub.global.exception.GlobalExceptionCode.EXPIRED_TOKEN; +import static com.spaceclub.global.exception.GlobalExceptionCode.EXPIRED_ACCESS_TOKEN; import static com.spaceclub.global.exception.GlobalExceptionCode.INVALID_ACCESS_TOKEN; @Slf4j @@ -68,7 +68,7 @@ public boolean isValidFormat(String token) { // 디코딩 try { jwtVerifier.verify(token); } catch (TokenExpiredException e) { - throw new AccessTokenException(EXPIRED_TOKEN); + throw new AccessTokenException(EXPIRED_ACCESS_TOKEN); } catch (JWTVerificationException e) { throw new AccessTokenException(INVALID_ACCESS_TOKEN); } diff --git a/src/main/java/com/spaceclub/global/jwt/JwtManager.java b/src/main/java/com/spaceclub/global/jwt/JwtManager.java index 359698aa..bfadb521 100644 --- a/src/main/java/com/spaceclub/global/jwt/JwtManager.java +++ b/src/main/java/com/spaceclub/global/jwt/JwtManager.java @@ -1,6 +1,7 @@ package com.spaceclub.global.jwt; import com.auth0.jwt.exceptions.JWTVerificationException; +import com.auth0.jwt.exceptions.TokenExpiredException; import com.spaceclub.global.exception.RefreshTokenException; import com.spaceclub.user.domain.User; import com.spaceclub.user.repository.UserRepository; @@ -8,6 +9,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import static com.spaceclub.global.exception.GlobalExceptionCode.EXPIRED_REFRESH_TOKEN; import static com.spaceclub.global.exception.GlobalExceptionCode.INVALID_REFRESH_TOKEN; import static com.spaceclub.user.UserExceptionMessage.USER_NOT_FOUND; @@ -45,6 +47,8 @@ public boolean isValidRefreshToken(String refreshToken, Long userId) { private void verifyRefreshToken(String refreshToken) { try { jwt.verify(refreshToken); + } catch (TokenExpiredException e) { + throw new RefreshTokenException(EXPIRED_REFRESH_TOKEN); } catch (JWTVerificationException e) { throw new RefreshTokenException(INVALID_REFRESH_TOKEN); }