Skip to content

Commit

Permalink
feat: ErrorType _JWT_PARSING_ERROR (#9)
Browse files Browse the repository at this point in the history
Jwt Parsing 예외 추가
  • Loading branch information
toychip committed Nov 29, 2023
1 parent 1b6469f commit 0a840db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/main/java/com/api/TaveShot/global/exception/ErrorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ public enum ErrorType {
* ex) "인증이 필요합니다."
*/

// ------------------------------------------ SERVER ------------------------------------------
_CANT_TRANCE_INSTANCE(INTERNAL_SERVER_ERROR, "SERVER_5000", "상수는 인스턴스화 할 수 없습니다."),
_SERVER_USER_NOT_FOUND(INTERNAL_SERVER_ERROR, "SERVER_5001", "로그인이 성공한 소셜 로그인 유저가 DB에 존재하지 않을 수 없습니다."),
_TOKEN_EXPIRED(UNAUTHORIZED, "JWT_4010", "Jwt Token의 유효 기간이 만료되었습니다.")
// 각종 에러들


// ---------------------------------------- JWT TOKEN ----------------------------------------
_JWT_PARSING_ERROR(BAD_REQUEST, "JWT_4001", "JWT 토큰 파싱 중 오류가 발생했습니다."),
_JWT_EXPIRED(UNAUTHORIZED, "JWT_4010", "Jwt Token의 유효 기간이 만료되었습니다."),



// ------------------------------------------ USER ------------------------------------------

;

private final HttpStatus status;
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/api/TaveShot/global/jwt/JwtProvider.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.api.TaveShot.global.jwt;

import static com.api.TaveShot.global.constant.OauthConstant.ACCESS_TOKEN_VALID_TIME;
import static com.api.TaveShot.global.exception.ErrorType._TOKEN_EXPIRED;
import static com.api.TaveShot.global.exception.ErrorType._JWT_EXPIRED;
import static com.api.TaveShot.global.exception.ErrorType._JWT_PARSING_ERROR;

import com.api.TaveShot.domain.Member.repository.MemberRepository;
import com.api.TaveShot.global.exception.ApiException;
Expand Down Expand Up @@ -67,9 +68,9 @@ public void isValidToken(final String jwtToken) {
.parseClaimsJws(jwtToken);

} catch (ExpiredJwtException e) { // 어세스 토큰 만료
throw new ApiException(_TOKEN_EXPIRED);
throw new ApiException(_JWT_EXPIRED);
} catch (Exception e) {
throw new IllegalArgumentException("User Not Authorized");
throw new ApiException(_JWT_PARSING_ERROR);
}
}

Expand Down

0 comments on commit 0a840db

Please sign in to comment.