KEEPER31337 / Homepage-Back-R2

키퍼 홈페이지 백엔드 리뉴얼 프로젝트입니다.

Home Page:https://keeper.or.kr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

inner Enum의 fromCode 메서드가 던지는 Exception을 수정한다.

shkisme opened this issue · comments

📝 Description

inner Enum이 존재하는 Entity가 있습니다. (Enum 대신 참조 테이블을 사용하고 있기 때문입니다.)
아래는 StaticWriteTitle 엔티티의 StaticWriteTitleType Enum 입니다.

@Getter
@RequiredArgsConstructor
public enum StaticWriteTitleType {
  INTRO(1, "키퍼(KEEPER) 소개글", "intro"),
  ACTIVITY(2, "정기 활동", "activity"),
  EXCELLENCE(3, "동아리 자랑", "excellence"),
  HISTORY(4, "동아리 연혁", "history");

  private final long id;
  private final String title;
  private final String type;

  public static StaticWriteTitleType fromCode(String type) {
    return Arrays.stream(StaticWriteTitleType.values())
        .filter(staticWriteTitleType -> staticWriteTitleType.getType().equals(type))
        .findAny()
        .orElseThrow(() -> new BusinessException(type, "type", TITLE_TYPE_NOT_FOUND));
  }
}

type에 해당하는 데이터를 찾을 수 없을 경우 BusinessException을 던지고 있습니다. 그러나 이는 비즈니스 로직 관련 예외가 아니므로, 적절한 Exception(IllegalArgumentException)을 던지도록 수정하는 게 좋을 것 같습니다.

☑️ TODO

  • 위와 같은 문제가 있는 inner Enum의 fromCode 메서드 찾아서 고치기
  • 해당하는 converter에서 catch 구문에서 잡는 Exception도 바꿔주기