-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 에러코드 규격화 #107
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: develop
Are you sure you want to change the base?
The head ref may contain hidden characters: "feature/106-error-code-standardization\u200B"
feat: 에러코드 규격화 #107
Changes from all commits
111296f
058cad6
877dfe4
bf6aeed
ee17e94
45afd82
845d214
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| package com.keunsori.keunsoriserver.global.exception; | ||
|
|
||
| public class AuthException extends RuntimeException { | ||
| import lombok.Getter; | ||
|
|
||
| public AuthException(String message) { | ||
| super(message); | ||
| @Getter | ||
| public class AuthException extends RuntimeException { | ||
| private ErrorCode errorCode; | ||
| public AuthException(ErrorCode errorCode) { | ||
| super(errorCode.getMassage()); | ||
| this.errorCode = errorCode; | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| package com.keunsori.keunsoriserver.global.exception; | ||
|
|
||
| public class EmailException extends RuntimeException { | ||
| import lombok.Getter; | ||
|
|
||
| public EmailException(String message) { | ||
| super(message); | ||
| @Getter | ||
| public class EmailException extends RuntimeException { | ||
| private ErrorCode errorCode; | ||
| public EmailException(ErrorCode errorCode) { | ||
| super(errorCode.getMassage()); | ||
| this.errorCode = errorCode; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.keunsori.keunsoriserver.global.exception; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public enum ErrorCode { | ||
| INVALID_INPUT_VALUE(400, "COMMON-001", "유효성 검증에 실패했습니다."), | ||
| INTERNAL_SERVER_ERROR(500,"COMMON-002", "서버에서 처리할 수 없습니다."), | ||
|
Comment on lines
+7
to
+8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. INTERNAL_ERROR(INTERNAL_SERVER_ERROR, "내부 서버 에러가 발생했습니다. 관리자에게 문의 바랍니다."),
METHOD_ARGUMENT_NULL(BAD_REQUEST, "인자는 null이 될 수 없습니다."),
METHOD_ARGUMENT_NOT_VALID(BAD_REQUEST, "인자가 유효하지 않습니다."),
REGEX_VIOLATION(BAD_REQUEST, "정규표현식을 위반했습니다."),
FORBIDDEN_ACCESS(FORBIDDEN, "접근 권한이 없습니다."),상태코드 숫자를 이렇게 상수로 적으면 가독성이 더 좋을 것 같은데 어떻게 생각하시나요?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은거 같습니다! 그럼 숫자는 상수로 적고 "COMMON-001" <- 이 도메인 코드는 그대로 남기면 되겟죠??
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 맞습니다! |
||
|
|
||
| // Member | ||
| MEMBER_NOT_EXISTS_WITH_STUDENT_ID(404, "MEMBER-001", "해당 학번을 가진 멤버가 존재하지 않습니다."), | ||
| DUPLICATED_STUDENT_ID(409, "MEMBER-002", "이미 존재하는 학번입니다."), | ||
| DUPLICATED_EMAIL(409, "MEMBER-003", "이미 존재하는 이메일입니다."), | ||
| PASSWORD_IS_DIFFERENT_FROM_CHECK(400, "MEMBER-004", "비밀번호와 비밀번호 확인 입력값이 다릅니다."), | ||
| PASSWORD_INVALID_FORMAT(400, "MEMBER-005", "비밀번호는 특수문자, 영문자, 숫자를 포함한 8자리 이상 문자열입니다."), | ||
| INVALID_CURRENT_PASSWORD(400, "MEMBER-006", "현재 비밀번호가 올바르지 않습니다."), | ||
| PASSWORD_SAME_AS_OLD(400, "MEMBER-007", "새 비밀번호가 기존 비밀번호와 동일합니다."), | ||
| STUDENT_ID_DOES_NOT_MATCH_WITH_EMAIL(400, "MEMBER-008", "가입한 학번과 이메일이 일치하지 않습니다"), | ||
|
|
||
| // Admin Member | ||
| INVALID_STATUS_FOR_APPROVAL(400, "ADMIN-MEMBER-001", "회원이 승인 대기 상태가 아닙니다."), | ||
|
|
||
| // Reservation | ||
| RESERVATION_NOT_EXISTS_WITH_ID(404, "RESERVATION-001", "해당 아이디 값을 가진 예약이 존재하지 않습니다."), | ||
| RESERVATION_NOT_EQUAL_MEMBER(403, "RESERVATION-002", "예약한 멤버가 아닙니다."), | ||
| RESERVATION_ALREADY_COMPLETED(400, "RESERVATION-003", "확정된 예약은 수정/취소할 수 없습니다."), | ||
| ANOTHER_RESERVATION_ALREADY_EXISTS(409, "RESERVATION-004", "해당 시간대에 다른 예약이 존재합니다."), | ||
| INVALID_RESERVATION_TIME(400, "RESERVATION-005", "예약 종료 시간은 예약 시작 시간보다 나중이어야 합니다."), | ||
| INVALID_RESERVATION_TYPE(400, "RESERVATION-006", "예약 타입이 잘못되었습니다."), | ||
| INVALID_RESERVATION_DATE(400, "RESERVATION-007", "예약 날짜는 과거 날짜면 안됩니다."), | ||
| INVALID_SESSION(404, "RESERVATION-008", "존재하지 않는 세션입니다."), | ||
|
|
||
| // Admin Reservation | ||
| INVALID_DATE_SCHEDULE(400, "ADMIN-RESERVATION-001", "설정하는 날짜가 이미 지난 날짜입니다."), | ||
| INVALID_SCHEDULE_TIME(400, "ADMIN-RESERVATION-002", "시작 시간과 끝 시간의 순서가 올바르지 않습니다."), | ||
|
|
||
| // Auth | ||
| STUDENT_ID_NOT_EXISTS(404, "AUTH-001", "존재하지 않는 학번입니다."), | ||
| INVALID_PASSWORD(401, "AUTH-002", "비밀번호가 일치하지 않습니다.") , | ||
| INVALID_REFRESH_TOKEN(401, "AUTH-003", "유효하지 않은 리프레시 토큰입니다."), | ||
| INVALID_TOKEN(401, "AUTH-004", "유효하지 않은 토큰입니다."), | ||
| EXPIRED_TOKEN(401, "AUTH-005", "만료된 토큰입니다."), | ||
|
|
||
| EMAIL_NOT_EXISTS_FOR_AUTH(400, "EMAIL-001", "인증번호를 전송하지 않았거나 인증번호가 만료되었습니다."), | ||
| EMAIL_VERIFY_FAILED(400, "EMAIL-002", "인증번호가 일치하지 않습니다."), | ||
| EMAIL_VERIFY_NUMBER_GENERATION_FAILED(500, "EMAIL-003", "인증번호 생성중 에러가 발생했습니다."); | ||
|
|
||
|
|
||
| private final int status; | ||
| private final String code; | ||
| private final String massage; | ||
|
|
||
| ErrorCode(int status, String code, String massage) { | ||
| this.status = status; | ||
| this.code = code; | ||
| this.massage = massage; | ||
| } | ||
| } | ||
This file was deleted.
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.
request 에서 검증 메서드의 상수화가 사라지는 부분이 아쉬운 것 같은데, 에러 메세지에 대한 상수와 에러 코드 포맷을 같이 가져가서, 에러 코드 포맷 내에서 상수 메세지를 같이 활용하는 건 어떻게 생각하시나요?
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.
STUDENT_ID_INVALID_FORMAT(null, "", "학번 형식이 올바르지 않습니다.");제가 이해한게 맞다면 ErrorCode에 요런 형식의 값을 추가해서 메시지 필드를 활용하는거 맞을까요??
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.
제가 말을 어렵게 적었었네요.. 에러메세지 상수 클래스와 에러 코드 포맷 같이 유지하는 방식 맞습니다!
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.
에러 코드 포맷 내의 메세지까지 상수 메세지를 활용하려니까 오히려 ErrorCode 클래스를 봤을 때 정보성이 떨어지는 것 같습니다...ㅠㅠ
Pattern에 들어가는 메세지만 상수화 시키고 에러 코드 포맷의 메세지는 문자열을 사용하는 건 어떨까요?
Uh oh!
There was an error while loading. Please reload this page.
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.
혹시
ErrorMessage.부분을 제거해도 (정적 임포트) 비슷하게 보일까요?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.
이런식으로 나오는데 이전에 있었던 상황처럼
프론트 측에서 백엔드에 잘못된 api 반환으로 "~"의 에러메세지가 온다 라고 확인 요청이 들어왔을 때
에러코드를 보면서 메세지를 확인하려면 에러메세지 클래스와 왔다갔다 하면서 확인해야 하는게 정보성이 떨어진다고 생각했습니다..!
+) 그리고 지금 에러코드와 연관된 에러메세지의 이름이 같아서 정적 임포트를 사용하려면 한쪽의 이름을 다 바꾸어야 하는 상황입니다ㅠ
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.
아하 그렇군요ㅠㅠ
그러면 말씀하신 방향대로 에러코드 포맷에서는 그냥 문자열을 사용하는 걸로 가죠 👍