Skip to content

Commit

Permalink
Fix: oauth 로그인 시 회원을 찾지 못한 경우에 반환하는 에러 타입을 변경 (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
WonSteps authored Nov 18, 2024
1 parent f134e93 commit a3cb9e3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "해당 엔티티를 찾을 수 없습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit a3cb9e3

Please sign in to comment.