Skip to content

Commit 912a984

Browse files
committed
fix: 중복 이메일 가입 에러 핸들링 추가
1 parent 7df7e0f commit 912a984

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.gotogether.global.oauth.exception;
2+
3+
import org.springframework.security.core.AuthenticationException;
4+
5+
public class DuplicatedEmailException extends AuthenticationException {
6+
public DuplicatedEmailException(String msg) {
7+
super(msg);
8+
}
9+
}

src/main/java/com/gotogether/global/oauth/handler/CustomFailureHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
77
import org.springframework.stereotype.Component;
88

9-
import com.gotogether.global.oauth.util.ErrorResponseUtil;
109
import com.gotogether.global.apipayload.code.status.ErrorStatus;
10+
import com.gotogether.global.oauth.exception.DuplicatedEmailException;
11+
import com.gotogether.global.oauth.util.ErrorResponseUtil;
1112

12-
import jakarta.servlet.ServletException;
1313
import jakarta.servlet.http.HttpServletRequest;
1414
import jakarta.servlet.http.HttpServletResponse;
1515

@@ -18,8 +18,12 @@ public class CustomFailureHandler implements AuthenticationFailureHandler {
1818

1919
@Override
2020
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
21-
AuthenticationException exception) throws IOException, ServletException {
21+
AuthenticationException exception) throws IOException {
2222

23-
ErrorResponseUtil.sendErrorResponse(response, ErrorStatus._INTERNAL_SERVER_ERROR);
23+
if (exception instanceof DuplicatedEmailException) {
24+
ErrorResponseUtil.sendErrorResponse(response, ErrorStatus._USER_EMAIL_ALREADY_EXISTS);
25+
} else {
26+
ErrorResponseUtil.sendErrorResponse(response, ErrorStatus._INTERNAL_SERVER_ERROR);
27+
}
2428
}
2529
}

src/main/java/com/gotogether/global/oauth/service/CustomOAuth2UserService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.gotogether.global.oauth.dto.KakaoResponseDTO;
2020
import com.gotogether.global.oauth.dto.OAuth2Response;
2121
import com.gotogether.global.oauth.dto.TokenDTO;
22+
import com.gotogether.global.oauth.exception.DuplicatedEmailException;
2223
import com.gotogether.global.oauth.util.JWTUtil;
2324
import com.gotogether.global.util.CookieUtil;
2425

@@ -64,7 +65,7 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
6465

6566
Optional<User> duplicateEmail = userRepository.findByEmail(oAuth2Response.getEmail());
6667
if (duplicateEmail.isPresent()) {
67-
throw new GeneralException(ErrorStatus._USER_EMAIL_ALREADY_EXISTS);
68+
throw new DuplicatedEmailException("이미 가입된 이메일입니다.");
6869
}
6970

7071
User userEntity = User.builder()

0 commit comments

Comments
 (0)