Skip to content

Commit dc9dd70

Browse files
committed
[fix] : 예외처리 수정
1 parent 0a1d61e commit dc9dd70

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.dfbf.soundlink.domain.user.exception;
2+
3+
public class CustomJwtException extends RuntimeException {
4+
public CustomJwtException(String message) {
5+
super(message);
6+
}
7+
8+
public CustomJwtException(String message, Throwable cause) {
9+
super(message, cause);
10+
}
11+
}

src/main/java/org/dfbf/soundlink/domain/user/exception/ExpiredTokenException.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/org/dfbf/soundlink/global/auth/JwtProvider.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.jsonwebtoken.security.Keys;
44
import jakarta.servlet.http.Cookie;
55
import jakarta.servlet.http.HttpServletRequest;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.dfbf.soundlink.domain.user.exception.CustomJwtException;
68
import org.springframework.beans.factory.annotation.Autowired;
79
import org.springframework.beans.factory.annotation.Value;
810
import org.springframework.data.redis.core.RedisTemplate;
@@ -13,6 +15,7 @@
1315
import java.util.Date;
1416
import java.util.concurrent.TimeUnit;
1517

18+
@Slf4j
1619
@Component
1720
public class JwtProvider {
1821

@@ -71,15 +74,14 @@ public boolean validateToken(String token) {
7174

7275
// 토큰이 유효한 경우
7376
return true;
74-
} catch (ExpiredJwtException e) {
75-
System.out.println("[ERROR] Token is expired.");
76-
throw e; // 만료된 토큰에 대해 예외를 던짐
77+
}catch (ExpiredJwtException e) {
78+
log.warn("[ERROR] Token is expired.");
79+
throw new CustomJwtException("토큰이 만료.", e);
7780
} catch (JwtException e) {
78-
System.out.println("[ERROR] Token validation failed: " + e.getMessage());
79-
throw e; // JWT 예외는 다시 던짐
81+
log.warn("[ERROR] Token validation failed: {}", e.getMessage());
82+
throw new CustomJwtException("토큰 검증 실패", e);
8083
} catch (Exception e) {
81-
System.out.println("[ERROR] Unexpected error: " + e.getMessage());
82-
throw new RuntimeException("Unexpected error", e);
84+
throw new CustomJwtException("예기치 않은 오류 발생", e);
8385
}
8486
}
8587

0 commit comments

Comments
 (0)