Skip to content

Commit dafe408

Browse files
committed
refect: custom error 추가 및 예외처리 보완
1 parent 4bb3c4d commit dafe408

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/main/java/com/back/domain/study/plan/service/StudyPlanService.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private enum UpdateType {
282282
@Transactional
283283
public StudyPlanResponse updateStudyPlan(Long userId, Long planId, StudyPlanRequest request, StudyPlanException.ApplyScope applyScope) {
284284
StudyPlan originalPlan = studyPlanRepository.findById(planId)
285-
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND));
285+
.orElseThrow(() -> new CustomException(ErrorCode.PLAN_NOT_FOUND));
286286

287287
validateUserAccess(originalPlan, userId);
288288

@@ -319,7 +319,7 @@ private UpdateType determineUpdateType(StudyPlan originalPlan, StudyPlanRequest
319319
return UpdateType.ORIGINAL_PLAN_UPDATE;
320320
}
321321

322-
// 1-2. 반복 계획에서 다른 날짜인 경우 -> 기존 예외 확인
322+
// 1-2. 반복 계획에서 다른 날짜인 경우 -> 기존 예외 존재 유무 확인
323323
Optional<StudyPlanException> existingException = studyPlanExceptionRepository
324324
.findByPlanIdAndDate(originalPlan.getId(), requestDate);
325325

@@ -353,7 +353,7 @@ private StudyPlanResponse createRepeatException(StudyPlan originalPlan, StudyPla
353353

354354
// 해당 날짜에 실제로 반복 계획이 있는지 확인
355355
if (!shouldRepeatOnDate(originalPlan, exceptionDate)) {
356-
throw new CustomException(ErrorCode.BAD_REQUEST);
356+
throw new CustomException(ErrorCode.PLAN_ORIGINAL_REPEAT_NOT_FOUND);
357357
}
358358

359359
StudyPlanException exception = new StudyPlanException();
@@ -380,7 +380,7 @@ private StudyPlanResponse createRepeatException(StudyPlan originalPlan, StudyPla
380380
LocalDate untilDate = LocalDate.parse(request.getRepeatRule().getUntilDate());
381381
embeddable.setUntilDate(untilDate);
382382
} catch (Exception e) {
383-
throw new CustomException(ErrorCode.BAD_REQUEST);
383+
throw new CustomException(ErrorCode.PLAN_INVALID_DATE_FORMAT);
384384
}
385385
}
386386

@@ -398,7 +398,7 @@ private StudyPlanResponse updateExistingException(StudyPlan originalPlan, StudyP
398398

399399
StudyPlanException existingException = studyPlanExceptionRepository
400400
.findByPlanIdAndDate(originalPlan.getId(), exceptionDate)
401-
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND));
401+
.orElse(null);
402402

403403
// 기존 예외 정보 업데이트
404404
if (request.getSubject() != null) existingException.setModifiedSubject(request.getSubject());
@@ -421,7 +421,7 @@ private StudyPlanResponse updateExistingException(StudyPlan originalPlan, StudyP
421421
LocalDate untilDate = LocalDate.parse(request.getRepeatRule().getUntilDate());
422422
embeddable.setUntilDate(untilDate);
423423
} catch (Exception e) {
424-
throw new CustomException(ErrorCode.BAD_REQUEST);
424+
throw new CustomException(ErrorCode.PLAN_INVALID_DATE_FORMAT);
425425
}
426426
}
427427

@@ -444,7 +444,7 @@ private void updateRepeatRule(RepeatRule repeatRule, StudyPlanRequest.RepeatRule
444444
LocalDate untilDate = LocalDate.parse(request.getUntilDate());
445445
repeatRule.setUntilDate(untilDate);
446446
} catch (Exception e) {
447-
throw new CustomException(ErrorCode.BAD_REQUEST);
447+
throw new CustomException(ErrorCode.PLAN_INVALID_DATE_FORMAT);
448448
}
449449
}
450450
}
@@ -453,7 +453,7 @@ private void updateRepeatRule(RepeatRule repeatRule, StudyPlanRequest.RepeatRule
453453
@Transactional
454454
public void deleteStudyPlan(Long userId, Long planId, LocalDate selectedDate, StudyPlanDeleteRequest request) {
455455
StudyPlan studyPlan = studyPlanRepository.findById(planId)
456-
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND));
456+
.orElseThrow(() -> new CustomException(ErrorCode.PLAN_NOT_FOUND));
457457

458458
validateUserAccess(studyPlan, userId);
459459

@@ -503,6 +503,4 @@ private void validateUserAccess(StudyPlan studyPlan, Long userId) {
503503
}
504504

505505

506-
507-
508506
}

src/main/java/com/back/global/exception/ErrorCode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public enum ErrorCode {
3232
CANNOT_KICK_HOST(HttpStatus.BAD_REQUEST, "ROOM_010", "방장은 추방할 수 없습니다."),
3333
CANNOT_CHANGE_HOST_ROLE(HttpStatus.BAD_REQUEST, "ROOM_011", "방장의 권한은 변경할 수 없습니다."),
3434

35+
// ======================== 스터디 플래너 관련 ========================
36+
PLAN_NOT_FOUND(HttpStatus.NOT_FOUND, "PLAN_001", "존재하지 않는 학습 계획입니다."),
37+
PLAN_FORBIDDEN(HttpStatus.FORBIDDEN, "PLAN_002", "학습 계획에 대한 접근 권한이 없습니다."),
38+
PLAN_EXCEPTION_NOT_FOUND(HttpStatus.NOT_FOUND, "PLAN_003", "학습 계획의 예외가 존재하지 않습니다."),
39+
PLAN_ORIGINAL_REPEAT_NOT_FOUND(HttpStatus.BAD_REQUEST, "PLAN_004", "해당 날짜에 원본 반복 계획을 찾을 수 없습니다."),
40+
PLAN_INVALID_DATE_FORMAT(HttpStatus.BAD_REQUEST, "PLAN_005", "날짜 형식이 올바르지 않습니다. (YYYY-MM-DD 형식을 사용해주세요)"),
41+
3542
// ======================== 메시지 관련 ========================
3643
MESSAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "MESSAGE_001", "존재하지 않는 메시지입니다."),
3744
MESSAGE_FORBIDDEN(HttpStatus.FORBIDDEN, "MESSAGE_002", "자신의 메시지만 삭제할 수 있습니다."),

0 commit comments

Comments
 (0)