From 0a840dbcc36063ff6ebb3296fedb8b5fb7731dd0 Mon Sep 17 00:00:00 2001 From: toychip Date: Thu, 30 Nov 2023 01:55:22 +0900 Subject: [PATCH] feat: ErrorType _JWT_PARSING_ERROR (#9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jwt Parsing 예외 추가 --- .../api/TaveShot/global/exception/ErrorType.java | 13 +++++++++++-- .../com/api/TaveShot/global/jwt/JwtProvider.java | 7 ++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/api/TaveShot/global/exception/ErrorType.java b/src/main/java/com/api/TaveShot/global/exception/ErrorType.java index a6befe0..b2939a7 100644 --- a/src/main/java/com/api/TaveShot/global/exception/ErrorType.java +++ b/src/main/java/com/api/TaveShot/global/exception/ErrorType.java @@ -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; diff --git a/src/main/java/com/api/TaveShot/global/jwt/JwtProvider.java b/src/main/java/com/api/TaveShot/global/jwt/JwtProvider.java index fe0c1e9..f702017 100644 --- a/src/main/java/com/api/TaveShot/global/jwt/JwtProvider.java +++ b/src/main/java/com/api/TaveShot/global/jwt/JwtProvider.java @@ -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; @@ -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); } }