Skip to content

Commit 615ea4f

Browse files
committed
feat: 커스텀 에러 추가 및 예외처리 적용
1 parent b4fa80c commit 615ea4f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/main/java/dmu/dasom/api/domain/common/exception/ErrorCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public enum ErrorCode {
3636
SLOT_NOT_ACTIVE(400, "C027", "해당 슬롯이 비활성화 되었습니다."),
3737
FILE_ENCODE_FAIL(400, "C028", "파일 인코딩에 실패하였습니다."),
3838
RECRUITMENT_NOT_ACTIVE(400, "C029", "모집 기간이 아닙니다."),
39-
NOT_FOUND_PARTICIPANT(400, "C030", "참가자를 찾을 수 없습니다.")
39+
NOT_FOUND_PARTICIPANT(400, "C030", "참가자를 찾을 수 없습니다."),
40+
EXECUTIVE_NOT_FOUND(400, "C031", "임원진을 찾을 수 없습니다."),
4041
;
4142

4243
private final int status;

src/main/java/dmu/dasom/api/domain/executive/service/ExecutiveService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dmu.dasom.api.domain.executive.service;
22

3+
import dmu.dasom.api.domain.common.exception.CustomException;
4+
import dmu.dasom.api.domain.common.exception.ErrorCode;
35
import dmu.dasom.api.domain.executive.dto.ExecutiveCreationResponseDto;
46
import dmu.dasom.api.domain.executive.dto.ExecutiveRequestDto;
57
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
@@ -21,7 +23,7 @@ public class ExecutiveService {
2123
// 이름, 직책, 깃허브 주소 검색
2224
public ExecutiveResponseDto getExecutiveById(Long id) {
2325
ExecutiveEntity executive = executiveRepository.findById(id)
24-
.orElseThrow(() -> new IllegalArgumentException("Executive not found")); // 일단 에러 코드 출력 나중에 커스텀 에러코드로 수정
26+
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
2527

2628
return executive.toResponseDto();
2729
}
@@ -35,7 +37,7 @@ public ExecutiveCreationResponseDto createExecutive(ExecutiveRequestDto requestD
3537
@Transactional
3638
public void deleteExective(Long id) {
3739
ExecutiveEntity executive = executiveRepository.findById(id)
38-
.orElseThrow(() -> new IllegalArgumentException("Executive not found")); // 일단 에러 코드 출력 나중에 커스텀 에러코드 수정
40+
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
3941

4042
executiveRepository.delete(executive);
4143
}
@@ -44,7 +46,7 @@ public void deleteExective(Long id) {
4446
@Transactional
4547
public ExecutiveResponseDto updateExecutive(Long id, ExecutiveUpdateRequestDto requestDto) {
4648
ExecutiveEntity executive = executiveRepository.findById(id)
47-
.orElseThrow(() -> new IllegalArgumentException("Executive not found")); // 임시 에러 코드 출력 나중에 커스텀 에러코드로 수정
49+
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
4850

4951
executive.update(requestDto.getName(), requestDto.getPosition(), requestDto.getGithubUrl());
5052

0 commit comments

Comments
 (0)