Skip to content

Commit 5f88143

Browse files
committed
♻️ refactor: 중간장소 예외처리 전역처리로 개선
1 parent ef76dc5 commit 5f88143

File tree

5 files changed

+34
-72
lines changed

5 files changed

+34
-72
lines changed

src/main/java/com/grepp/spring/app/model/schedule/service/ScheduleCommandService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.grepp.spring.app.model.schedule.repository.WorkspaceCommandRepository;
5353
import com.grepp.spring.app.model.schedule.repository.WorkspaceQueryRepository;
5454
import com.grepp.spring.infra.error.exceptions.schedule.EventNotActivatedException;
55+
import com.grepp.spring.infra.error.exceptions.schedule.VoteAlreadyProgressException;
5556
import com.grepp.spring.infra.utils.RandomPicker;
5657
import com.grepp.spring.infra.error.exceptions.NotFoundException;
5758
import com.grepp.spring.infra.error.exceptions.group.UserNotFoundException;
@@ -557,7 +558,7 @@ public void WriteSuggestedLocation(Schedule schedule, WriteSuggestedLocationRequ
557558
}
558559
}
559560
else {
560-
throw new RuntimeException("투표중입니다! 투표중에는 후보장소를 등록할 수 없습니다.");
561+
throw new VoteAlreadyProgressException(ScheduleErrorCode.VOTE_ALREADY_PROGRESS);
561562
}
562563

563564
}

src/main/java/com/grepp/spring/infra/error/RestApiExceptionAdvice.java

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.grepp.spring.infra.error.exceptions.schedule;
2+
3+
import com.grepp.spring.infra.response.ScheduleErrorCode;
4+
import lombok.extern.slf4j.Slf4j;
5+
6+
@Slf4j
7+
public class VoteAlreadyProgressException extends RuntimeException {
8+
private final ScheduleErrorCode code;
9+
10+
public VoteAlreadyProgressException(ScheduleErrorCode code) {
11+
this.code = code;
12+
}
13+
14+
public VoteAlreadyProgressException(ScheduleErrorCode code, Exception e) {
15+
this.code = code;
16+
log.error(e.getMessage(), e);
17+
}
18+
19+
public ScheduleErrorCode code() {
20+
return code;
21+
}
22+
}

src/main/java/com/grepp/spring/infra/error/scheduleAdvuce/ScheduleExceptionAdvice.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
@Order(1)
2222
public class ScheduleExceptionAdvice {
2323

24+
@ExceptionHandler(VoteAlreadyProgressException.class)
25+
public ResponseEntity<ApiResponse<String>> notScheduleMemberExHandler(
26+
VoteAlreadyProgressException ex) {
27+
28+
return ResponseEntity.status(HttpStatus.CONFLICT)
29+
.body(ApiResponse.error(ScheduleErrorCode.VOTE_ALREADY_PROGRESS));
30+
}
31+
2432
@ExceptionHandler(NotScheduleMemberException.class)
2533
public ResponseEntity<ApiResponse<String>> notScheduleMemberExHandler(
2634
NotScheduleMemberException ex) {

src/main/java/com/grepp/spring/infra/response/ScheduleErrorCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ public enum ScheduleErrorCode {
88
SCHEDULE_MEMBER_NOT_FOUND("404",HttpStatus.NOT_FOUND, "스케줄에서 회원을 찾을 수 없습니다."),
99
WORKSPACE_NOT_FOUND("404",HttpStatus.NOT_FOUND,"워크스페이스를 찾을 수 없습니다."),
1010
EVENT_NOT_ACTIVATED("409", HttpStatus.CONFLICT, "이미 일정이 생성된 이벤트입니다."),
11-
NOT_SCHEDULE_MEMBER("403",HttpStatus.FORBIDDEN,"일정에 포함된 멤버만 조회할 수 있습니다.");
11+
NOT_SCHEDULE_MEMBER("403",HttpStatus.FORBIDDEN,"일정에 포함된 멤버만 조회할 수 있습니다."),
12+
VOTE_ALREADY_PROGRESS("409",HttpStatus.CONFLICT,"투표중입니다! 투표중에는 후보장소를 등록할 수 없습니다.");
1213

1314
private final String code;
1415
private final HttpStatus status;

0 commit comments

Comments
 (0)