Skip to content

Commit

Permalink
[VACGOM-146] feat: 소셜 로그인 예외 응답 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
whereami2048 committed Jan 15, 2025
1 parent 78de101 commit 28aaaa0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/kr/co/vacgom/api/user/exception/AuthError.kt
Original file line number Diff line number Diff line change
@@ -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"),
}

0 comments on commit 28aaaa0

Please sign in to comment.