handler Error 추가

This commit is contained in:
ckx6954 2025-01-22 18:57:47 +09:00
parent d7ceef7d70
commit 83a62afc8d
2 changed files with 3 additions and 2 deletions

View File

@ -20,6 +20,7 @@ import io.company.localhost.common.exception.code.UserErrorCode;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -39,7 +40,7 @@ public class MemberAuthFailureHandler implements AuthenticationFailureHandler {
ApiResponse<?> res = UserErrorCode.BAD_CREDENTIAL.getApiResponse(); ApiResponse<?> res = UserErrorCode.BAD_CREDENTIAL.getApiResponse();
String message = exception.getMessage(); String message = exception.getMessage();
if (message.startsWith("NOT_FOUND")) { if (exception instanceof BadCredentialsException || message.startsWith("NOT_FOUND")) {
res = UserErrorCode.USER_NOT_FOUND.getApiResponse(); res = UserErrorCode.USER_NOT_FOUND.getApiResponse();
} else if (message.startsWith("NOT_AUTHORIZED")) { } else if (message.startsWith("NOT_AUTHORIZED")) {
res = UserErrorCode.NOT_AUTHORIZED.getApiResponse(); res = UserErrorCode.NOT_AUTHORIZED.getApiResponse();

View File

@ -34,7 +34,7 @@ public class MemberPrincipalDetailService implements UserDetailsService {
public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {
MemberVo member = memberMapper.findByLoginId(id); MemberVo member = memberMapper.findByLoginId(id);
// 없을경우 에러 발생 //FailHandler 에서 처리
if(member == null) if(member == null)
throw new UsernameNotFoundException("NOT_FOUND"); throw new UsernameNotFoundException("NOT_FOUND");