Skip to content

Commit

Permalink
fix: use custom Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
great-park committed Jul 20, 2023
1 parent 4a3e2b1 commit 0a5f85b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package swm.hkcc.LGTM.app.modules.auth.exception;

import swm.hkcc.LGTM.app.global.constant.ResponseCode;
import swm.hkcc.LGTM.app.global.exception.GeneralException;

public class InvalidAuthentication extends GeneralException {
public InvalidAuthentication() {
super(ResponseCode.INVALID_AUTHENTICATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import swm.hkcc.LGTM.app.modules.auth.exception.InvalidAuthentication;
import swm.hkcc.LGTM.app.modules.member.domain.Member;
import swm.hkcc.LGTM.app.modules.member.domain.custom.CustomUserDetails;
import swm.hkcc.LGTM.app.modules.member.repository.MemberRepository;
Expand All @@ -20,9 +21,8 @@ public class CustomUserDetailsService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String githubId) throws UsernameNotFoundException {
log.info("username: " + githubId);
Member member = memberRepository.findOneByGithubId(githubId).orElseThrow(
() -> new UsernameNotFoundException("Invalid authentication!")
);
Member member = memberRepository.findOneByGithubId(githubId)
.orElseThrow(InvalidAuthentication::new);

return new CustomUserDetails(member);
}
Expand Down

0 comments on commit 0a5f85b

Please sign in to comment.