diff --git a/src/main/java/io/company/localhost/common/security/handler/MemberAuthFailureHandler.java b/src/main/java/io/company/localhost/common/security/handler/MemberAuthFailureHandler.java index 3acbd4d..b978aaa 100644 --- a/src/main/java/io/company/localhost/common/security/handler/MemberAuthFailureHandler.java +++ b/src/main/java/io/company/localhost/common/security/handler/MemberAuthFailureHandler.java @@ -20,6 +20,7 @@ import io.company.localhost.common.exception.code.UserErrorCode; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.http.MediaType; +import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.stereotype.Component; @@ -39,7 +40,7 @@ public class MemberAuthFailureHandler implements AuthenticationFailureHandler { ApiResponse res = UserErrorCode.BAD_CREDENTIAL.getApiResponse(); String message = exception.getMessage(); - if (message.startsWith("NOT_FOUND")) { + if (exception instanceof BadCredentialsException || message.startsWith("NOT_FOUND")) { res = UserErrorCode.USER_NOT_FOUND.getApiResponse(); } else if (message.startsWith("NOT_AUTHORIZED")) { res = UserErrorCode.NOT_AUTHORIZED.getApiResponse(); diff --git a/src/main/java/io/company/localhost/common/security/service/MemberPrincipalDetailService.java b/src/main/java/io/company/localhost/common/security/service/MemberPrincipalDetailService.java index 3a6b9b4..07e1171 100644 --- a/src/main/java/io/company/localhost/common/security/service/MemberPrincipalDetailService.java +++ b/src/main/java/io/company/localhost/common/security/service/MemberPrincipalDetailService.java @@ -34,7 +34,7 @@ public class MemberPrincipalDetailService implements UserDetailsService { public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { MemberVo member = memberMapper.findByLoginId(id); - // 없을경우 에러 발생 + //FailHandler 에서 처리 if(member == null) throw new UsernameNotFoundException("NOT_FOUND");