From a3cb9e3b98327ec3842d12a36955aa46204f9f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=EC=9B=90?= Date: Mon, 18 Nov 2024 15:53:19 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20oauth=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=9C=20=ED=9A=8C=EC=9B=90=EC=9D=84=20=EC=B0=BE=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=9C=20=EA=B2=BD=EC=9A=B0=EC=97=90=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=ED=95=98=EB=8A=94=20=EC=97=90=EB=9F=AC=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=9D=84=20=EB=B3=80=EA=B2=BD=20(#307)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dnd/runus/application/oauth/SocialProfileService.java | 6 ++++-- .../java/com/dnd/runus/global/exception/type/ErrorType.java | 2 +- .../dnd/runus/presentation/v1/oauth/OauthController.java | 2 +- .../com/dnd/runus/application/oauth/OauthServiceTest.java | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/dnd/runus/application/oauth/SocialProfileService.java b/src/main/java/com/dnd/runus/application/oauth/SocialProfileService.java index 9e0ffcb7..3b63b38b 100644 --- a/src/main/java/com/dnd/runus/application/oauth/SocialProfileService.java +++ b/src/main/java/com/dnd/runus/application/oauth/SocialProfileService.java @@ -6,7 +6,8 @@ import com.dnd.runus.domain.member.SocialProfileRepository; import com.dnd.runus.global.constant.MemberRole; import com.dnd.runus.global.constant.SocialType; -import com.dnd.runus.global.exception.NotFoundException; +import com.dnd.runus.global.exception.BusinessException; +import com.dnd.runus.global.exception.type.ErrorType; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,7 +31,8 @@ public boolean isSocialMemberExists(SocialType socialType, String oauthId, long public SocialProfile findOrThrow(SocialType socialType, String oauthId, String email) { SocialProfile socialProfile = socialProfileRepository .findBySocialTypeAndOauthId(socialType, oauthId) - .orElseThrow(() -> new NotFoundException(SocialProfile.class, oauthId)); + .orElseThrow(() -> + new BusinessException(ErrorType.SOCIAL_MEMBER_NOT_FOUND, socialType + ", oauthId: " + oauthId)); updateEmailIfChanged(socialProfile, email); return socialProfile; diff --git a/src/main/java/com/dnd/runus/global/exception/type/ErrorType.java b/src/main/java/com/dnd/runus/global/exception/type/ErrorType.java index a4f78051..aaf85004 100644 --- a/src/main/java/com/dnd/runus/global/exception/type/ErrorType.java +++ b/src/main/java/com/dnd/runus/global/exception/type/ErrorType.java @@ -32,7 +32,7 @@ public enum ErrorType { INVALID_CREDENTIALS(UNAUTHORIZED, DEBUG, "AUTH_008", "해당 사용자의 정보가 없거나 일치하지 않아 처리할 수 없습니다"), // OauthErrorType - USER_NOT_FOUND(NOT_FOUND, DEBUG, "OAUTH_001", "존재하지 않은 사용자 입니다"), + SOCIAL_MEMBER_NOT_FOUND(NOT_FOUND, DEBUG, "OAUTH_001", "찾을 수 없는 소셜 회원입니다"), // DatabaseErrorType ENTITY_NOT_FOUND(NOT_FOUND, DEBUG, "DB_001", "해당 엔티티를 찾을 수 없습니다"), diff --git a/src/main/java/com/dnd/runus/presentation/v1/oauth/OauthController.java b/src/main/java/com/dnd/runus/presentation/v1/oauth/OauthController.java index 7b6833db..bb32b91e 100644 --- a/src/main/java/com/dnd/runus/presentation/v1/oauth/OauthController.java +++ b/src/main/java/com/dnd/runus/presentation/v1/oauth/OauthController.java @@ -39,7 +39,7 @@ public class OauthController { """) @ApiErrorType({ ErrorType.UNSUPPORTED_SOCIAL_TYPE, - ErrorType.USER_NOT_FOUND, + ErrorType.SOCIAL_MEMBER_NOT_FOUND, ErrorType.FAILED_AUTHENTICATION, ErrorType.UNSUPPORTED_JWT_TOKEN }) diff --git a/src/test/java/com/dnd/runus/application/oauth/OauthServiceTest.java b/src/test/java/com/dnd/runus/application/oauth/OauthServiceTest.java index 50a9d8bc..786a06dd 100644 --- a/src/test/java/com/dnd/runus/application/oauth/OauthServiceTest.java +++ b/src/test/java/com/dnd/runus/application/oauth/OauthServiceTest.java @@ -108,7 +108,7 @@ void socialProfile_exist_then_signIn_success() { } @Test - @DisplayName("sign-in 시 socialProfile이 없다면 에러 타입이 USER_NOT_FOUND인 BusinessException 에러 발생") + @DisplayName("sign-in 시 socialProfile이 없다면 에러 타입이 SOCIAL_MEMBER_NOT_FOUND인 BusinessException 에러 발생") void socialProfile_not_exist_then_signIn_fail() { // given SignInRequest request = new SignInRequest(socialType, idToken); @@ -117,11 +117,11 @@ void socialProfile_not_exist_then_signIn_fail() { given(claims.getSubject()).willReturn(oauthId); given(claims.get("email")).willReturn(email); given(socialProfileService.findOrThrow(socialType, oauthId, email)) - .willThrow(new BusinessException(ErrorType.USER_NOT_FOUND)); + .willThrow(new BusinessException(ErrorType.SOCIAL_MEMBER_NOT_FOUND)); // when, then BusinessException exception = assertThrows(BusinessException.class, () -> oauthService.signIn(request)); - assertEquals(ErrorType.USER_NOT_FOUND, exception.getType()); + assertEquals(ErrorType.SOCIAL_MEMBER_NOT_FOUND, exception.getType()); } @Test