Skip to content

Commit

Permalink
feat: MemberNotFoundException 구현 및 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjy committed May 3, 2024
1 parent 813bc39 commit 8802d7f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.rollthedice.backend.domain.member.exception;

import com.rollthedice.backend.global.error.ErrorCode;
import com.rollthedice.backend.global.error.exception.BusinessException;

public class MemberNotFoundException extends BusinessException {
public MemberNotFoundException() {
super(ErrorCode.MEMBER_NOT_FOUND_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.rollthedice.backend.domain.member.service;

import com.rollthedice.backend.domain.member.dto.MemberServiceDto;
import com.rollthedice.backend.domain.member.dto.SignUpDto;
import com.rollthedice.backend.domain.member.dto.response.MemberResponse;
import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.member.exception.MemberNotFoundException;
import com.rollthedice.backend.domain.member.repository.MemberRepository;
import com.rollthedice.backend.global.oauth2.service.AuthService;
import com.rollthedice.backend.global.security.jwt.refresh.service.RefreshTokenService;
import com.rollthedice.backend.global.security.jwt.service.JwtService;
import jakarta.persistence.EntityNotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -38,7 +37,7 @@ public void update(MemberServiceDto memberServiceDto) {

@Transactional(readOnly = true)
public Member findByEmail(String email) {
return memberRepository.findByEmail(email).orElseThrow(EntityNotFoundException::new);
return memberRepository.findByEmail(email).orElseThrow(MemberNotFoundException::new);
}

public MemberResponse getMemberInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ public enum ErrorCode {
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "내부 서버에 오류가 발생했습니다."),
CLOVA_API_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "CLOVA API 호출에 실패했습니다."),

// MEMBER
MEMBER_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "회원 정보를 찾지 못했습니다." ),

// NEWS
NEWS_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "뉴스를 찾지 못했습니다."),

// DEBATE
DEBATE_ROOM_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "토론방을 찾지 못했습니다.");


private final HttpStatus status;
private final String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import com.rollthedice.backend.domain.member.entity.Member;
import com.rollthedice.backend.domain.member.entity.Role;
import com.rollthedice.backend.domain.member.entity.SocialType;
import com.rollthedice.backend.domain.member.exception.MemberNotFoundException;
import com.rollthedice.backend.domain.member.repository.MemberRepository;
import com.rollthedice.backend.global.oauth2.dto.LoginRequest;
import com.rollthedice.backend.global.oauth2.userInfo.OAuth2UserInfo;
import com.rollthedice.backend.global.security.jwt.service.JwtService;
import com.rollthedice.backend.global.query.QueryService;
import jakarta.persistence.EntityNotFoundException;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -54,7 +54,7 @@ public Member getMember() {

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
return memberRepository.findByEmail(userDetails.getUsername()).orElseThrow(EntityNotFoundException::new);
return memberRepository.findByEmail(userDetails.getUsername()).orElseThrow(MemberNotFoundException::new);
}

}

0 comments on commit 8802d7f

Please sign in to comment.