From dd67864ccd3909190859f986c6ae7d334b7a337b Mon Sep 17 00:00:00 2001 From: min-0 Date: Fri, 6 Sep 2024 04:47:17 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=ED=9A=8C=EC=9B=90=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EA=B4=80=EB=A0=A8=20custum=20Exception=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AppleTokenRevokeException 생성 후 Handler에 추가 --- .../auth/exception/AppleTokenRevokeException.java | 9 +++++++++ .../dndtravel/auth/service/AppleOAuthService.java | 3 ++- .../dnd/dndtravel/common/CommonExceptionHandler.java | 12 ++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/dnd/dndtravel/auth/exception/AppleTokenRevokeException.java diff --git a/src/main/java/com/dnd/dndtravel/auth/exception/AppleTokenRevokeException.java b/src/main/java/com/dnd/dndtravel/auth/exception/AppleTokenRevokeException.java new file mode 100644 index 0000000..113f71a --- /dev/null +++ b/src/main/java/com/dnd/dndtravel/auth/exception/AppleTokenRevokeException.java @@ -0,0 +1,9 @@ +package com.dnd.dndtravel.auth.exception; + +public class AppleTokenRevokeException extends RuntimeException { + private static final String MESSAGE = "Error revoking Apple token"; + + public AppleTokenRevokeException(Exception e) { + super(MESSAGE, e); + } +} diff --git a/src/main/java/com/dnd/dndtravel/auth/service/AppleOAuthService.java b/src/main/java/com/dnd/dndtravel/auth/service/AppleOAuthService.java index 0589eca..d0372ed 100644 --- a/src/main/java/com/dnd/dndtravel/auth/service/AppleOAuthService.java +++ b/src/main/java/com/dnd/dndtravel/auth/service/AppleOAuthService.java @@ -1,5 +1,6 @@ package com.dnd.dndtravel.auth.service; +import com.dnd.dndtravel.auth.exception.AppleTokenRevokeException; import com.dnd.dndtravel.auth.service.dto.response.AppleSocialTokenInfoResponse; import io.jsonwebtoken.JwsHeader; import io.jsonwebtoken.Jwts; @@ -105,7 +106,7 @@ public void revoke(String accessToken) { "access_token" ); } catch (Exception e) { - throw new RuntimeException("Error revoking Apple token", e); + throw new AppleTokenRevokeException(e); } } } diff --git a/src/main/java/com/dnd/dndtravel/common/CommonExceptionHandler.java b/src/main/java/com/dnd/dndtravel/common/CommonExceptionHandler.java index ca037c8..5239702 100644 --- a/src/main/java/com/dnd/dndtravel/common/CommonExceptionHandler.java +++ b/src/main/java/com/dnd/dndtravel/common/CommonExceptionHandler.java @@ -1,15 +1,12 @@ package com.dnd.dndtravel.common; +import com.dnd.dndtravel.auth.exception.*; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import com.dnd.dndtravel.auth.exception.AppleTokenDecodingException; -import com.dnd.dndtravel.auth.exception.JwtTokenDecodingException; -import com.dnd.dndtravel.auth.exception.JwtTokenExpiredException; -import com.dnd.dndtravel.auth.exception.RefreshTokenInvalidException; import com.dnd.dndtravel.map.exception.MemberAttractionNotFoundException; import com.dnd.dndtravel.map.exception.MemberNotFoundException; import com.dnd.dndtravel.map.exception.PhotoDeleteFailException; @@ -63,6 +60,13 @@ public ResponseEntity runtimeException(AppleTokenDecodingException e) { .body("토큰 인증에 실패했습니다"); } + @ExceptionHandler(AppleTokenRevokeException.class) + public ResponseEntity runtimeException(AppleTokenRevokeException e) { + return ResponseEntity + .status(HttpStatus.UNAUTHORIZED) + .body("토큰 인증에 실패했습니다"); + } + @ExceptionHandler(JwtTokenExpiredException.class) public ResponseEntity runtimeException(JwtTokenExpiredException e) { return ResponseEntity