Skip to content

Commit

Permalink
fix: 내부 로직 보강 및 예외 처리 전략 보강
Browse files Browse the repository at this point in the history
- Core의 검증로직 추가
- 예외의 스택트레이스를 보기 위해 GeneralException 생성자 추가
- GeneralException의 예외 스택트레이스를 로그로 남기기 위해 GlobalExceptionHandler 수정
  • Loading branch information
tmdcheol committed Oct 3, 2024
1 parent bf1401e commit 73d589b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/main/java/icurriculum/domain/curriculum/data/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public void validate() {
if (isAreaFixed == null || requiredCredit == null) {
throw new GeneralException(ErrorStatus.CURRICULUM_MISSING_VALUE, this);
}
if (!isAreaFixed && !requiredAreaSet.isEmpty()) {
throw new GeneralException(ErrorStatus.CORE_INVALID_DATA, this);
}
if (isAreaFixed && requiredAreaSet.isEmpty()) {
throw new GeneralException(ErrorStatus.CORE_INVALID_DATA, this);
}
}

private void validateCategory(Category category) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ private Set<Course> handleAreaAlternative(
while (iterator.hasNext()) {
Take take = iterator.next();

for (Category area : core.getRequiredAreaSet()) {
Set<Category> requiredAreaSet = getRequiredAreaSetWhenHandleAreaAlt(core);
for (Category area : requiredAreaSet) {
Set<String> areaAlternativeCodeSet = core.getAreaAlternativeCodeSet(area);

if (GraduationUtils.isApproved(take, areaAlternativeCodeSet)) {
Expand All @@ -85,6 +86,13 @@ private Set<Course> handleAreaAlternative(
return areaAltCourseSet;
}

private Set<Category> getRequiredAreaSetWhenHandleAreaAlt(Core core) {
if (!core.getIsAreaFixed()) {
return GraduationUtils.CORE_CATEGORYSET;
}
return core.getRequiredAreaSet();
}

/*
* [core logic]
* - 영역 대체를 통해서 이미 계산된 과목은 건너뛴다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ public GeneralException(ErrorStatus errorStatus, Object data) {
this.data = data;
}

}
public GeneralException(ErrorStatus errorStatus, Throwable cause) {
super(errorStatus.getMessage(), cause);
this.errorStatus = errorStatus;
this.data = null;
}

public GeneralException(ErrorStatus errorStatus, Object data, Throwable cause) {
super(errorStatus.getMessage(), cause);
this.errorStatus = errorStatus;
this.data = data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
@RestControllerAdvice
public class GlobalExceptionHandler {

/*
* 비즈니스적으로 에러가 발생했을 때 사용됩니다.
*/
@ExceptionHandler(GeneralException.class)
public ResponseEntity<ApiResponse<Object>> handleGeneralException(GeneralException ex) {
log.error("Error Code: {}, Message: {}, Data: {}",
ex.getErrorStatus().getCode(),
ex.getErrorStatus().getMessage(),
ex.getData() != null ? ex.getData() : "No additional data");
ex.getData() != null ? ex.getData() : "No additional data",
ex
);

return ResponseEntity
.status(ex.getErrorStatus().getHttpStatus())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public enum ErrorStatus {
CURRICULUM_NOT_VALID_CATEGORY(HttpStatus.BAD_REQUEST, "CURRICULUM402",
"CurriculumCode 에는 전공필수, 전공선택, 교양필수 조회가능합니다."),
CORE_NOT_VALID_CATEGORY(HttpStatus.BAD_REQUEST, "CURRICULUM403",
"Core 에는 핵심교양만 조회가능합니다."),
CURRICULUM_MISSING_VALUE(HttpStatus.BAD_REQUEST, "CURRICULUM404",
"Core는 핵심교양만 조회가능합니다."),
CORE_INVALID_DATA(HttpStatus.BAD_REQUEST, "CURRICULUM404",
"Core의 데이터형식이 올바르지 않습니다."),
CURRICULUM_MISSING_VALUE(HttpStatus.BAD_REQUEST, "CURRICULUM405",
"Curriculum 내부의 필수값이 빠졌습니다."),
CURRICULUM_DECIDER_MISSING_VALUE(HttpStatus.BAD_REQUEST, "CURRICULUM405",
CURRICULUM_DECIDER_MISSING_VALUE(HttpStatus.BAD_REQUEST, "CURRICULUM406",
"CurriculumDecider 내부의 필수값이 빠졌습니다."),

/*
Expand Down

0 comments on commit 73d589b

Please sign in to comment.