Skip to content

[✨feat] InternshipAnnouncement 커스텀 예외 적용 #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: feat/#46
Choose a base branch
from

Conversation

jsoonworld
Copy link
Member

📄 Work Description

  • InternshipErrorCode enum을 도입하여 마감일, 스크랩 수, 조회수에 대한 도메인 유효성 검증 메시지를 코드화함
  • InternshipException을 정의하여 도메인 전용 예외를 BaseException을 통해 처리
  • 기존 require 문을 제거하고, 각 도메인에서 커스텀 예외를 사용하여 검증 실패 시 명확한 예외를 던지도록 변경

💭 Thoughts

커스텀 예외를 사용하는 방식이 나중에 공통적으로 예외를 관리하거나 응답 포맷을 정형화하는 데에는 확실히 유리하다고 느꼈습니다.
다만, 현재 도메인 규칙들이 비교적 단순한 편이어서 지금 단계에서 커스텀 예외를 도입하는 것이 과하지 않은지 고민이 되기도 했습니다.
이 부분에 대해 유빈님의 의견을 듣고 싶습니다!

require를 사용하는 방식

장점

  • 간결하고 빠르게 작성 가능
  • 표준 예외(IllegalArgumentException)로 충분한 경우가 많음
  • 간단한 유효성 검증에는 불필요한 커스텀 클래스를 줄일 수 있음

단점

  • 예외의 의미가 불명확할 수 있음 (IllegalArgumentException만으로는 원인을 알기 어려움)
  • 에러 코드 및 메시지의 일관성 유지가 어려움
  • API 레벨에서 정형화된 에러 응답 제공이 힘듦

커스텀 예외를 사용하는 방식

장점

  • 예외의 의미와 출처가 명확해짐 (예: InternshipException)
  • 도메인 중심 설계에 적합 (비즈니스 규칙 위반을 구체적으로 표현 가능)
  • 에러 코드 및 메시지를 enum으로 통합 관리 가능
  • 공통 예외 핸들러에서 에러 메시지와 상태 코드를 일관되게 응답 가능

단점

  • 클래스 수 증가로 인해 코드가 다소 무거워질 수 있음
  • 단순 검증에는 과할 수 있음

➡️ 이번 변경에서는 도메인 규칙이 명확히 존재하는 영역(예: 마감일 제한, 스크랩 수 감소 제한)이므로, 명시적인 InternshipException을 통해 도메인 규칙을 명확하게 표현하는 방향이 더 적절하다고 판단했습니다.

✅ Testing Result

스크린샷

🗂 Related Issue

- 마감일, 스크랩 수, 조회수에 대한 도메인 유효성 검증용 에러 코드 추가
- BaseErrorCode 인터페이스를 구현하여 상태 코드와 메시지를 일관되게 관리
- InternshipErrorCode를 인자로 받아 BaseException을 상속하는 도메인 전용 예외 정의
- 인턴십 마감일, 스크랩 수, 조회수 등의 비즈니스 검증 실패 시 사용
- Deadline, ScrapCount, ViewCount에서 require를 제거하고 InternshipException으로 명확한 예외 처리 적용
- 각 예외 상황에 맞는 InternshipErrorCode를 통해 일관된 에러 메시지와 상태 코드 제공
- 도메인 규칙 위반을 명확하게 드러내는 구조로 개선
- decrease() 호출 시 발생하는 예외가 IllegalArgumentException에서 InternshipException으로 변경됨에 따라 테스트 수정
- 도메인 유효성 검증 방식 변경 사항을 테스트 코드에 반영
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements custom exception handling for the InternshipAnnouncement domain by replacing standard validation checks with domain-specific exceptions.

  • Replaces require statements with explicit if-checks that throw InternshipException using InternshipErrorCode.
  • Updates tests to assert the new custom exception.
  • Introduces InternshipException and InternshipErrorCode for uniform error management.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ScrapCountTest.kt Updated test to expect InternshipException instead of IllegalArgumentException.
ViewCount.kt Changed validation from require to an explicit if-check that throws InternshipException.
ScrapCount.kt Revised validation checks to throw InternshipException on invalid scrap count operations.
InternshipException.kt Introduced a custom exception class for internship domain errors.
InternshipErrorCode.kt Defined domain-specific error codes and messages for internship announcements.
Deadline.kt Updated deadline validation to throw InternshipException when the deadline is not after Jan 1, 2025.

Copy link
Member

@leeeyubin leeeyubin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고민해주신 점에 대해 장단점을 잘 적어주셔서 이해하기 편했던 것 같아요!👍

저는 "커스텀 예외"를 적용하는 방식이 더 좋을 것 같습니다..!
현재 코드에 있어서 과해 보일지라도 추후 확장성을 고려했을 때 커스텀 예외를 통해 일관되게 응답을 해 주는 것이 더 좋을 것 같다는 의견입니다!

Comment on lines +12 to +13
if (value.isAfter(LocalDate.of(2025, 1, 1)).not()) {
throw InternshipException(InternshipErrorCode.INVALID_DEADLINE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not 이라는 함수는 처음 보는 것 같네요..!
!와 같은 의미인 걸까요?
보통 조건문에서는 !로 좀 더 간결하고 직관적이게 나타낼 수 있을 것 같은데 not 함수를 사용해주신 이유가 궁금합니다!

Comment on lines 9 to 13
init {
require(value >= MIN_VALUE) { INVALID_SCRAP_COUNT_MESSAGE }
if (value < MIN_VALUE) {
throw InternshipException(InternshipErrorCode.INVALID_SCRAP_COUNT)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init 안에 들어가는 부분도 함수화를 해주면 어떤 코드인지 이해하기 편할 것 같아요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants