diff --git a/src/main/java/com/wedit/weditapp/global/auth/login/handler/OAuth2LoginFailureHandler.java b/src/main/java/com/wedit/weditapp/global/auth/login/handler/OAuth2LoginFailureHandler.java new file mode 100644 index 0000000..5e874ff --- /dev/null +++ b/src/main/java/com/wedit/weditapp/global/auth/login/handler/OAuth2LoginFailureHandler.java @@ -0,0 +1,22 @@ +package com.wedit.weditapp.global.auth.login.handler; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Slf4j +@Component +public class OAuth2LoginFailureHandler implements AuthenticationFailureHandler { + @Override + public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.getWriter().write("소셜 로그인 실패! 서버 로그를 확인해주세요."); + log.info("소셜 로그인에 실패했습니다. 에러 메시지 : {}", exception.getMessage()); + } +}