-
Notifications
You must be signed in to change notification settings - Fork 7
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
[Feature/BE] 예외 상황시 예외 코드를 반환 #298
Changes from 1 commit
18e6863
2c982c4
4a06295
4841efe
d2d6154
eb55a55
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,24 +1,28 @@ | ||
package com.woowacourse.f12.dto.response; | ||
|
||
import com.woowacourse.f12.exception.CustomException; | ||
import com.woowacourse.f12.exception.ErrorCode; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ExceptionResponse { | ||
|
||
private String message; | ||
private ErrorCode errorCode; | ||
|
||
private ExceptionResponse() { | ||
} | ||
|
||
private ExceptionResponse(final String message) { | ||
private ExceptionResponse(final String message, final ErrorCode errorCode) { | ||
this.message = message; | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public static ExceptionResponse from(final Exception e) { | ||
return new ExceptionResponse(e.getMessage()); | ||
public static ExceptionResponse from(final CustomException e) { | ||
return new ExceptionResponse(e.getMessage(), e.getErrorCode()); | ||
} | ||
|
||
public static ExceptionResponse from(final String message) { | ||
return new ExceptionResponse(message); | ||
public static ExceptionResponse from(final String message, final ErrorCode errorCode) { | ||
return new ExceptionResponse(message, errorCode); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.woowacourse.f12.exception; | ||
|
||
public class CustomException extends RuntimeException { | ||
|
||
private final ErrorCode errorCode; | ||
|
||
public CustomException(final String message, final ErrorCode errorCode) { | ||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public ErrorCode getErrorCode() { | ||
return errorCode; | ||
} | ||
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. 롬복의 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. 적용했습니다 |
||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||
package com.woowacourse.f12.exception; | ||||||||||
|
||||||||||
import com.fasterxml.jackson.annotation.JsonValue; | ||||||||||
|
||||||||||
public enum ErrorCode { | ||||||||||
|
||||||||||
INVALID_SEARCH_PARAM("40000"), | ||||||||||
INVALID_REQUEST_BODY("40001"), | ||||||||||
INVALID_TOKEN("40002"), | ||||||||||
DUPLICATED_CONTENT("40003"), | ||||||||||
BLANK_CONTENT("40004"), | ||||||||||
NOT_ENOUGH_DATA("40005"), | ||||||||||
|
||||||||||
TOKEN_NOT_EXISTS("40100"), | ||||||||||
TOKEN_EXPIRED("400101"), | ||||||||||
TOKEN_INVALID("400102"), | ||||||||||
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. 이 두 곳의 에러코드만 6자리군요!! 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. 수정했습니다. 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.
Suggested change
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. 수정했습니다. |
||||||||||
|
||||||||||
PERMISSION_DENIED("40300"), | ||||||||||
|
||||||||||
DATA_NOT_FOUND("40400"), | ||||||||||
|
||||||||||
INTERNAL_SERVER_ERROR("50000"), | ||||||||||
EXTERNAL_SERVER_ERROR("50001"); | ||||||||||
|
||||||||||
private final String value; | ||||||||||
|
||||||||||
ErrorCode(final String value) { | ||||||||||
this.value = value; | ||||||||||
} | ||||||||||
|
||||||||||
@JsonValue | ||||||||||
public String getValue() { | ||||||||||
return value; | ||||||||||
} | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.DUPLICATED_CONTENT; | ||
|
||
public class AlreadyWrittenReviewException extends InvalidValueException { | ||
|
||
public AlreadyWrittenReviewException() { | ||
super("해당 제품에 대해 이미 리뷰가 작성되어 있습니다."); | ||
super("해당 제품에 대해 이미 리뷰가 작성되어 있습니다.", DUPLICATED_CONTENT); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.BLANK_CONTENT; | ||
|
||
public class BlankContentException extends InvalidValueException { | ||
|
||
public BlankContentException() { | ||
super("리뷰 내용은 공백이 될 수 없습니다."); | ||
super("리뷰 내용은 공백이 될 수 없습니다.", BLANK_CONTENT); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_SEARCH_PARAM; | ||
|
||
public class InvalidCareerLevelException extends InvalidValueException { | ||
|
||
public InvalidCareerLevelException() { | ||
super("올바르지 않은 연차 입력입니다."); | ||
super("올바르지 않은 연차 입력입니다.", INVALID_SEARCH_PARAM); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_SEARCH_PARAM; | ||
|
||
public class InvalidCategoryValueException extends InvalidValueException { | ||
|
||
public InvalidCategoryValueException() { | ||
super("잘못된 카테고리입니다."); | ||
super("잘못된 카테고리입니다.", INVALID_SEARCH_PARAM); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_REQUEST_BODY; | ||
|
||
public class InvalidContentLengthException extends InvalidValueException { | ||
|
||
public InvalidContentLengthException(final int maxLength) { | ||
super("내용의 길이는 " + maxLength + "자 이하 여야 합니다."); | ||
super("내용의 길이는 " + maxLength + "자 이하 여야 합니다.", INVALID_REQUEST_BODY); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_SEARCH_PARAM; | ||
|
||
public class InvalidGitHubLoginException extends InvalidValueException { | ||
|
||
public InvalidGitHubLoginException() { | ||
super("잘못된 GitHub 로그인 요청입니다."); | ||
super("잘못된 GitHub 로그인 요청입니다.", INVALID_SEARCH_PARAM); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import com.woowacourse.f12.exception.ErrorCode; | ||
|
||
public class InvalidJobTypeException extends InvalidValueException { | ||
|
||
public InvalidJobTypeException() { | ||
super("올바르지 않은 직군 입력입니다."); | ||
super("올바르지 않은 직군 입력입니다.", ErrorCode.INVALID_SEARCH_PARAM); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_SEARCH_PARAM; | ||
|
||
public class InvalidPageNumberFormatException extends InvalidValueException { | ||
|
||
public InvalidPageNumberFormatException() { | ||
super("페이지 번호는 숫자 형식이여야 합니다."); | ||
super("페이지 번호는 숫자 형식이여야 합니다.", INVALID_SEARCH_PARAM); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_SEARCH_PARAM; | ||
|
||
public class InvalidPageSizeException extends InvalidValueException { | ||
|
||
public InvalidPageSizeException(int maxSize) { | ||
super("페이지의 크기는" + maxSize + "이하여야 합니다."); | ||
super("페이지의 크기는" + maxSize + "이하여야 합니다.", INVALID_SEARCH_PARAM); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_SEARCH_PARAM; | ||
|
||
public class InvalidPageSizeFormatException extends InvalidValueException { | ||
|
||
public InvalidPageSizeFormatException() { | ||
super("패이지 크기는 숫자 형식이어야 합니다."); | ||
super("패이지 크기는 숫자 형식이어야 합니다.", INVALID_SEARCH_PARAM); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
|
||
import static com.woowacourse.f12.exception.ErrorCode.NOT_ENOUGH_DATA; | ||
|
||
public class InvalidProfileArgumentException extends InvalidValueException { | ||
|
||
public InvalidProfileArgumentException() { | ||
super("추가 정보가 등록되지 않았습니다."); | ||
super("추가 정보가 등록되지 않았습니다.", NOT_ENOUGH_DATA); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_REQUEST_BODY; | ||
|
||
public class InvalidProfileProductException extends InvalidValueException { | ||
|
||
public InvalidProfileProductException() { | ||
super("유효하지 않은 대표 장비 수정 요청입니다."); | ||
super("유효하지 않은 대표 장비 수정 요청입니다.", INVALID_REQUEST_BODY); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.INVALID_REQUEST_BODY; | ||
|
||
public class InvalidRatingValueException extends InvalidValueException { | ||
|
||
public InvalidRatingValueException() { | ||
super("평점은 1에서 5 사이여야 합니다."); | ||
super("평점은 1에서 5 사이여야 합니다.", INVALID_REQUEST_BODY); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.woowacourse.f12.exception.badrequest; | ||
|
||
public class InvalidValueException extends RuntimeException { | ||
import com.woowacourse.f12.exception.CustomException; | ||
import com.woowacourse.f12.exception.ErrorCode; | ||
|
||
public InvalidValueException(final String message) { | ||
super(message); | ||
public class InvalidValueException extends CustomException { | ||
|
||
public InvalidValueException(final String message, final ErrorCode errorCode) { | ||
super(message, errorCode); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.woowacourse.f12.exception.forbidden; | ||
|
||
public class ForbiddenMemberException extends RuntimeException { | ||
import com.woowacourse.f12.exception.CustomException; | ||
import com.woowacourse.f12.exception.ErrorCode; | ||
|
||
public ForbiddenMemberException(final String message) { | ||
super(message); | ||
public class ForbiddenMemberException extends CustomException { | ||
|
||
public ForbiddenMemberException(final String message, final ErrorCode errorCode) { | ||
super(message, errorCode); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.forbidden; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.PERMISSION_DENIED; | ||
|
||
public class NotAuthorException extends ForbiddenMemberException { | ||
|
||
public NotAuthorException() { | ||
super("리뷰의 작성자가 아닙니다."); | ||
super("리뷰의 작성자가 아닙니다.", PERMISSION_DENIED); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.woowacourse.f12.exception.internalserver; | ||
|
||
public class ExternalServerException extends RuntimeException { | ||
import com.woowacourse.f12.exception.CustomException; | ||
import com.woowacourse.f12.exception.ErrorCode; | ||
|
||
public ExternalServerException(final String message) { | ||
super(message); | ||
public class ExternalServerException extends CustomException { | ||
|
||
public ExternalServerException(final String message, final ErrorCode errorCode) { | ||
super(message, errorCode); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.woowacourse.f12.exception.internalserver; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.EXTERNAL_SERVER_ERROR; | ||
|
||
public class GitHubServerException extends ExternalServerException { | ||
|
||
public GitHubServerException() { | ||
super("GitHub 서버에 문제가 있습니다."); | ||
super("GitHub 서버에 문제가 있습니다.", EXTERNAL_SERVER_ERROR); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.woowacourse.f12.exception.notfound; | ||
|
||
import static com.woowacourse.f12.exception.ErrorCode.DATA_NOT_FOUND; | ||
|
||
public class InventoryProductNotFoundException extends NotFoundException { | ||
|
||
public InventoryProductNotFoundException() { | ||
super("등록 장비를 찾을 수 없습니다.", DATA_NOT_FOUND); | ||
} | ||
} |
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.
생성자 매개변수 순서를 바꾸겠습니다.