-
Notifications
You must be signed in to change notification settings - Fork 0
[✨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
base: feat/#46
Are you sure you want to change the base?
Conversation
- 마감일, 스크랩 수, 조회수에 대한 도메인 유효성 검증용 에러 코드 추가 - BaseErrorCode 인터페이스를 구현하여 상태 코드와 메시지를 일관되게 관리
- InternshipErrorCode를 인자로 받아 BaseException을 상속하는 도메인 전용 예외 정의 - 인턴십 마감일, 스크랩 수, 조회수 등의 비즈니스 검증 실패 시 사용
- Deadline, ScrapCount, ViewCount에서 require를 제거하고 InternshipException으로 명확한 예외 처리 적용 - 각 예외 상황에 맞는 InternshipErrorCode를 통해 일관된 에러 메시지와 상태 코드 제공 - 도메인 규칙 위반을 명확하게 드러내는 구조로 개선
- decrease() 호출 시 발생하는 예외가 IllegalArgumentException에서 InternshipException으로 변경됨에 따라 테스트 수정 - 도메인 유효성 검증 방식 변경 사항을 테스트 코드에 반영
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고민해주신 점에 대해 장단점을 잘 적어주셔서 이해하기 편했던 것 같아요!👍
저는 "커스텀 예외
"를 적용하는 방식이 더 좋을 것 같습니다..!
현재 코드에 있어서 과해 보일지라도 추후 확장성을 고려했을 때 커스텀 예외를 통해 일관되게 응답을 해 주는 것이 더 좋을 것 같다는 의견입니다!
if (value.isAfter(LocalDate.of(2025, 1, 1)).not()) { | ||
throw InternshipException(InternshipErrorCode.INVALID_DEADLINE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not
이라는 함수는 처음 보는 것 같네요..!
!
와 같은 의미인 걸까요?
보통 조건문에서는 !
로 좀 더 간결하고 직관적이게 나타낼 수 있을 것 같은데 not
함수를 사용해주신 이유가 궁금합니다!
init { | ||
require(value >= MIN_VALUE) { INVALID_SCRAP_COUNT_MESSAGE } | ||
if (value < MIN_VALUE) { | ||
throw InternshipException(InternshipErrorCode.INVALID_SCRAP_COUNT) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init
안에 들어가는 부분도 함수화를 해주면 어떤 코드인지 이해하기 편할 것 같아요!
📄 Work Description
InternshipErrorCode
enum을 도입하여 마감일, 스크랩 수, 조회수에 대한 도메인 유효성 검증 메시지를 코드화함InternshipException
을 정의하여 도메인 전용 예외를BaseException
을 통해 처리require
문을 제거하고, 각 도메인에서 커스텀 예외를 사용하여 검증 실패 시 명확한 예외를 던지도록 변경💭 Thoughts
커스텀 예외를 사용하는 방식이 나중에 공통적으로 예외를 관리하거나 응답 포맷을 정형화하는 데에는 확실히 유리하다고 느꼈습니다.
다만, 현재 도메인 규칙들이 비교적 단순한 편이어서 지금 단계에서 커스텀 예외를 도입하는 것이 과하지 않은지 고민이 되기도 했습니다.
이 부분에 대해 유빈님의 의견을 듣고 싶습니다!
require
를 사용하는 방식장점
IllegalArgumentException
)로 충분한 경우가 많음단점
IllegalArgumentException
만으로는 원인을 알기 어려움)커스텀 예외를 사용하는 방식
장점
InternshipException
)enum
으로 통합 관리 가능단점
➡️ 이번 변경에서는 도메인 규칙이 명확히 존재하는 영역(예: 마감일 제한, 스크랩 수 감소 제한)이므로, 명시적인
InternshipException
을 통해 도메인 규칙을 명확하게 표현하는 방향이 더 적절하다고 판단했습니다.✅ Testing Result
🗂 Related Issue