Merged
Conversation
yeonju73
approved these changes
Jul 9, 2025
Contributor
yeonju73
left a comment
There was a problem hiding this comment.
아이고~ 수고하셨습니다~~ 저도 잘 형식 맞춰서 해보겠습니다
Comment on lines
+9
to
+31
| @Getter | ||
| public enum SwaggerResponseDescription { | ||
| REGISTER_FAIL(new LinkedHashSet<>(Set.of( | ||
| ErrorCode.DUPLICATED_EMAIL | ||
| ))), | ||
|
|
||
| LOGIN_FAIL(new LinkedHashSet<>(Set.of( | ||
| ErrorCode.INVALID_EMAIL, | ||
| ErrorCode.INVALID_PASSWORD | ||
| ))); | ||
|
|
||
| private final Set<ErrorCode> errorCodeList; | ||
|
|
||
| SwaggerResponseDescription(Set<ErrorCode> errorCodes) { | ||
| // 공통 에러 추가 | ||
| errorCodes.addAll(Set.of( | ||
| ErrorCode.INVALID_TOKEN, | ||
| ErrorCode.INTERNAL_SERVER_ERROR | ||
| )); | ||
|
|
||
| this.errorCodeList = errorCodes; | ||
| } | ||
| } |
Comment on lines
+9
to
+23
| public enum ErrorCode { | ||
| /// 4000 ~ : client error | ||
| DUPLICATED_EMAIL(HttpStatus.BAD_REQUEST, 4001, "이미 가입된 이메일입니다."), | ||
| INVALID_EMAIL(HttpStatus.BAD_REQUEST, 4002, "존재하지 않는 이메일입니다."), | ||
| INVALID_PASSWORD(HttpStatus.BAD_REQUEST, 4003, "비밀번호가 일치하지 않습니다."), | ||
| INVALID_TOKEN(HttpStatus.UNAUTHORIZED, 4004, "유효하지 않은 토큰입니다."), | ||
|
|
||
| // 5000~ : server error | ||
| INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000, "서버 오류가 발생했습니다."); | ||
|
|
||
| private final HttpStatus status; | ||
| private final int code; | ||
| private final String msg; | ||
|
|
||
| } |
Contributor
There was a problem hiding this comment.
ErrorCode 넘버링은 그냥 구현한 순서대로 하면될까요?
Comment on lines
+8
to
+12
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface CustomExceptionDescription { | ||
| SwaggerResponseDescription value(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💻 Related Issue
closed #6
🚀 Work Description
ErrorCode,SuccessCode: error code와 success code를 enum으로 정의BaseResponse: 기본 응답 구조 정의 ex) code, msg, dataErrorResponse: 에러 응답 구조 정의Global Exception Handler 이 링크를 참고해서 작성하였습니다.
사진과 같이 성공 예시 응답 코드와 함께 각 코드 별 에러 코드 추가
SwaggerResponseDescription: 발생 에러 코드 정의 < 하나의 기능에 발생하는 에러 코드들을 묶어서 표시 & 공통 에러 추가 -> api 에@CustomExceptionDescription(SwaggerResponseDescription.REGISTER_FAIL)이런식으로 추가하면 관련 에러 응답 & 공통 에러 응답 예시 뜸🙇🏻♀️ To Reviewer
우선 스웨거 관련 코드들은 config > swagger 로 옮겨놨는데 필요하다면 패키지 구조 정리하면 될 것 같습니다.!
그리고 우선 예외 처리 및 스웨거 문서화 하였는데 구조 바꾸거나 이상한 부분 있으면 말씀해주세요!! 저도 처음해보는거라 헷갈리네요 ㅠ ㅠ
추가로 이전 pr에서 남겨주신 개선 사항들 적용하였습니다!
+) error code에 예외 값 추가한 다음에 service 로직에서 사용하면됩니다. 그리고 스웨거에 연동하기 위해서는 SwaggerResponseDescription에 추가해서 api에
@CustomExceptionDescription붙여서 사용하시면 됩니다. 혹시 이상하거나 헷갈리는 부분 있으시면 말씀해주세요!