From 28aaaa04240b78c3459a90cbd2cf3720f65238e3 Mon Sep 17 00:00:00 2001 From: whereami2048 Date: Wed, 15 Jan 2025 17:43:22 +0900 Subject: [PATCH] =?UTF-8?q?[VACGOM-146]=20feat:=20=EC=86=8C=EC=85=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=98=88=EC=99=B8=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/auth/oauth/kakao/KakaoOAuthStrategy.kt | 15 +++++++++++++-- .../kr/co/vacgom/api/user/exception/AuthError.kt | 13 +++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/kr/co/vacgom/api/user/exception/AuthError.kt diff --git a/src/main/kotlin/kr/co/vacgom/api/auth/oauth/kakao/KakaoOAuthStrategy.kt b/src/main/kotlin/kr/co/vacgom/api/auth/oauth/kakao/KakaoOAuthStrategy.kt index 463001e..8b27b46 100644 --- a/src/main/kotlin/kr/co/vacgom/api/auth/oauth/kakao/KakaoOAuthStrategy.kt +++ b/src/main/kotlin/kr/co/vacgom/api/auth/oauth/kakao/KakaoOAuthStrategy.kt @@ -1,7 +1,11 @@ package kr.co.vacgom.api.auth.oauth.kakao +import feign.FeignException import kr.co.vacgom.api.auth.oauth.OAuthStrategy import kr.co.vacgom.api.auth.oauth.dto.SocialAuthInfo +import kr.co.vacgom.api.global.exception.error.BusinessException +import kr.co.vacgom.api.global.exception.error.GlobalError +import kr.co.vacgom.api.user.exception.AuthError import kr.co.vacgom.api.user.presentation.dto.LoginDto import org.springframework.stereotype.Component @@ -12,8 +16,15 @@ class KakaoOAuthStrategy( ): OAuthStrategy { override fun getUserInfo(request: LoginDto.Request.Social): SocialAuthInfo { - val kakaoUserInfo = kakaoFeignClient.getUserInfo(BEARER_PREFIX + request.accessToken) - return SocialAuthInfo(kakaoUserInfo.id) + return runCatching { + val kakaoUserInfo = kakaoFeignClient.getUserInfo(BEARER_PREFIX + request.accessToken) + SocialAuthInfo(kakaoUserInfo.id) + }.onFailure { + when (it) { + is FeignException.Unauthorized -> throw BusinessException(AuthError.FEIGN_UNAUTHORIZED) + else -> throw BusinessException(GlobalError.INTERNAL_SERVER_ERROR) + } + }.getOrThrow() } override fun revokeUser(socialId: String) { diff --git a/src/main/kotlin/kr/co/vacgom/api/user/exception/AuthError.kt b/src/main/kotlin/kr/co/vacgom/api/user/exception/AuthError.kt new file mode 100644 index 0000000..458439b --- /dev/null +++ b/src/main/kotlin/kr/co/vacgom/api/user/exception/AuthError.kt @@ -0,0 +1,13 @@ +package kr.co.vacgom.api.user.exception + +import kr.co.vacgom.api.global.exception.error.ErrorCode +import org.springframework.http.HttpStatus +import org.springframework.http.HttpStatus.NOT_FOUND + +enum class AuthError( + override val message: String, + override val status: HttpStatus, + override val code: String, +) : ErrorCode { + FEIGN_UNAUTHORIZED("유효하지 않은 엑세스 토큰 입니다.", NOT_FOUND, "A_001"), +}