Skip to content

Commit

Permalink
feat: 로그인 에러 처리 #11
Browse files Browse the repository at this point in the history
  • Loading branch information
jjt4515 committed Sep 23, 2024
1 parent 9993c25 commit 4483f99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import poomasi.domain.member.dto.response.LoginResponse;
import poomasi.domain.member.repository.MemberRepository;
import poomasi.domain.member.entity.Member;
import poomasi.global.error.BusinessException;
import poomasi.global.util.JwtUtil;

import java.util.HashMap;
import java.util.Map;

import static poomasi.domain.member.entity.LoginType.LOCAL;
import static poomasi.global.error.BusinessError.INVALID_CREDENTIAL;
import static poomasi.global.error.BusinessError.MEMBER_NOT_FOUND;

@Service
public class MemberService {
Expand All @@ -28,10 +31,10 @@ public MemberService(JwtUtil jwtUtil) {

public LoginResponse login(LoginRequest loginRequest) {
Member member = memberRepository.findByEmailAndLoginType(loginRequest.email(), LOCAL)
.orElseThrow(() -> new MemberNotFoundExeption(MEMBER_NOT_FOUND));
.orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND));

if (!new BCryptPasswordEncoder().matches(loginRequest.password(), member.getPassword())) {
throw new InvalidCredentialsException(INVALID_CREDENTIAL);
throw new BusinessException(INVALID_CREDENTIAL);
}

Map<String, Object> claims = new HashMap<>();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/poomasi/global/error/BusinessError.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
@Getter
@AllArgsConstructor
public enum BusinessError {
EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "에러 예시입니다.");
EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "에러 예시입니다."),
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "회원이 존재하지 않습니다."),
INVALID_CREDENTIAL(HttpStatus.UNAUTHORIZED, "잘못된 비밀번호 입니다.");

private final HttpStatus httpStatus;

Expand Down

0 comments on commit 4483f99

Please sign in to comment.