-
Notifications
You must be signed in to change notification settings - Fork 3
[feat] 커스텀 예외 공통 처리 #41
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
Conversation
backend/src/main/java/io/f1/backend/domain/game/dto/request/RoomCreateRequest.java
Outdated
Show resolved
Hide resolved
jiwon1217
left a comment
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.
에러 코드도 도메인 마다 나누니까, 에러 코드를 변경하거나 추가할 때 작업이 용이하겠네요 👍
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.
[L4-변경제안]
JSON 자체가 형식이 잘못됐을 때 (콤마, 괄호 누락 등), 요청 바디가 빈 JSON ("" 또는 {} 없이 아예 없을 때), 타입이 잘못됐을 때 (int인데 문자열이 들어온 경우)를 처리할 수 있는 HttpMessageNotReadableException 예외도 핸들링하면 좋을 것 같습니다 !
[L5-참고의견] |
말씀하신 것처럼 타입에 대한 입력 예외 처리도 있어야할 것 같네요! 추가 해놓겠습니다 감사합니다!👍 |
silver-eunjoo
left a comment
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.
고생하셨습니다 ! 도메인별로 나눠져있어서 정말 보기 좋은 것 같아요 ! 👍
sehee123
left a comment
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.
수고하셨습니다! 🙌
🛰️ Issue Number
Closes #35
🪐 작업 내용
에러코드
에러코드는 공통 에러처리와 도메인별로 Enum클래스를 나누어 놓았습니다. 에러코드가 많지 않은 경우, 하나에 몰아넣고 주석으로 구분하는 경우가 많은데, 분리하는 경우가 각 도메인별 책임분리도 되고,
위 코드와 같이 유지보수나 가독성에 도움이 된다고 판단하였습니다.
글로벌 예외 처리 로직 - GlobalHandlerException
→ CustomException 을 잡아서, 예외에 담긴 커스텀 에러코드와 메시지, HTTP 상태코드를 사용해 응답을 만들어서 내려줍니다.
즉, 직접 정의한 비즈니스 예외 처리용입니다.
→ Exception 클래스(모든 예외의 최상위)를 잡아서, 정의하지 않은 모든 예외에 대해 500 서버 에러 응답을 내려줍니다.
즉, 의도하지 않은 에러, 예상하지 못한 에러를 위한 보험입니다.
→ @Valid 검증 실패 시 발생하는 MethodArgumentNotValidException 을 잡아, 필드별 에러 메시지 중 첫 번째를 뽑아 BAD_REQUEST 코드와 함께 반환합니다.
📚 Reference
✅ Check List