generated from pricelees/issue-pr-template
[#5]: 공통 기능 코틀린 마이그레이션 및 패키지 분리 #6
@ -1,74 +1,70 @@
|
|||||||
package roomescape.common.exception;
|
package roomescape.common.exception
|
||||||
|
|
||||||
import java.util.Arrays;
|
import com.fasterxml.jackson.annotation.JsonCreator
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
enum class ErrorType(
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
@JvmField val description: String
|
||||||
|
) {
|
||||||
|
// 400 Bad Request
|
||||||
|
REQUEST_DATA_BLANK("요청 데이터에 유효하지 않은 값(null OR 공백)이 포함되어있습니다."),
|
||||||
|
INVALID_REQUEST_DATA_TYPE("요청 데이터 형식이 올바르지 않습니다."),
|
||||||
|
INVALID_REQUEST_DATA("요청 데이터 값이 올바르지 않습니다."),
|
||||||
|
INVALID_DATE_RANGE("종료 날짜는 시작 날짜 이전일 수 없습니다."),
|
||||||
|
HAS_RESERVATION_OR_WAITING("같은 테마에 대한 예약(대기)는 한 번만 가능합니다."),
|
||||||
|
|
||||||
public enum ErrorType {
|
// 401 Unauthorized
|
||||||
|
EXPIRED_TOKEN("토큰이 만료되었습니다. 다시 로그인 해주세요."),
|
||||||
|
UNSUPPORTED_TOKEN("지원하지 않는 JWT 토큰입니다."),
|
||||||
|
MALFORMED_TOKEN("형식이 맞지 않는 JWT 토큰입니다."),
|
||||||
|
INVALID_SIGNATURE_TOKEN("잘못된 JWT 토큰 Signature 입니다."),
|
||||||
|
ILLEGAL_TOKEN("JWT 토큰의 Claim 이 비어있습니다."),
|
||||||
|
INVALID_TOKEN("JWT 토큰이 존재하지 않거나 유효하지 않습니다."),
|
||||||
|
NOT_EXIST_COOKIE("쿠키가 존재하지 않습니다. 로그인이 필요한 서비스입니다."),
|
||||||
|
|
||||||
// 400 Bad Request
|
// 403 Forbidden
|
||||||
REQUEST_DATA_BLANK("요청 데이터에 유효하지 않은 값(null OR 공백)이 포함되어있습니다."),
|
LOGIN_REQUIRED("로그인이 필요한 서비스입니다."),
|
||||||
INVALID_REQUEST_DATA_TYPE("요청 데이터 형식이 올바르지 않습니다."),
|
PERMISSION_DOES_NOT_EXIST("접근 권한이 존재하지 않습니다."),
|
||||||
INVALID_REQUEST_DATA("요청 데이터 값이 올바르지 않습니다."),
|
|
||||||
INVALID_DATE_RANGE("종료 날짜는 시작 날짜 이전일 수 없습니다."),
|
|
||||||
HAS_RESERVATION_OR_WAITING("같은 테마에 대한 예약(대기)는 한 번만 가능합니다."),
|
|
||||||
|
|
||||||
// 401 Unauthorized
|
// 404 Not Found
|
||||||
EXPIRED_TOKEN("토큰이 만료되었습니다. 다시 로그인 해주세요."),
|
MEMBER_NOT_FOUND("회원(Member) 정보가 존재하지 않습니다."),
|
||||||
UNSUPPORTED_TOKEN("지원하지 않는 JWT 토큰입니다."),
|
RESERVATION_NOT_FOUND("예약(Reservation) 정보가 존재하지 않습니다."),
|
||||||
MALFORMED_TOKEN("형식이 맞지 않는 JWT 토큰입니다."),
|
RESERVATION_TIME_NOT_FOUND("예약 시간(ReservationTime) 정보가 존재하지 않습니다."),
|
||||||
INVALID_SIGNATURE_TOKEN("잘못된 JWT 토큰 Signature 입니다."),
|
THEME_NOT_FOUND("테마(Theme) 정보가 존재하지 않습니다."),
|
||||||
ILLEGAL_TOKEN("JWT 토큰의 Claim 이 비어있습니다."),
|
PAYMENT_NOT_POUND("결제(Payment) 정보가 존재하지 않습니다."),
|
||||||
INVALID_TOKEN("JWT 토큰이 존재하지 않거나 유효하지 않습니다."),
|
|
||||||
NOT_EXIST_COOKIE("쿠키가 존재하지 않습니다. 로그인이 필요한 서비스입니다."),
|
|
||||||
|
|
||||||
// 403 Forbidden
|
// 405 Method Not Allowed
|
||||||
LOGIN_REQUIRED("로그인이 필요한 서비스입니다."),
|
METHOD_NOT_ALLOWED("지원하지 않는 HTTP Method 입니다."),
|
||||||
PERMISSION_DOES_NOT_EXIST("접근 권한이 존재하지 않습니다."),
|
|
||||||
|
|
||||||
// 404 Not Found
|
// 409 Conflict
|
||||||
MEMBER_NOT_FOUND("회원(Member) 정보가 존재하지 않습니다."),
|
TIME_IS_USED_CONFLICT("삭제할 수 없는 시간대입니다. 예약이 존재하는지 확인해주세요."),
|
||||||
RESERVATION_NOT_FOUND("예약(Reservation) 정보가 존재하지 않습니다."),
|
THEME_IS_USED_CONFLICT("삭제할 수 없는 테마입니다. 예약이 존재하는지 확인해주세요."),
|
||||||
RESERVATION_TIME_NOT_FOUND("예약 시간(ReservationTime) 정보가 존재하지 않습니다."),
|
TIME_DUPLICATED("이미 해당 시간이 존재합니다."),
|
||||||
THEME_NOT_FOUND("테마(Theme) 정보가 존재하지 않습니다."),
|
THEME_DUPLICATED("같은 이름의 테마가 존재합니다."),
|
||||||
PAYMENT_NOT_POUND("결제(Payment) 정보가 존재하지 않습니다."),
|
RESERVATION_DUPLICATED("해당 시간에 이미 예약이 존재합니다."),
|
||||||
|
RESERVATION_PERIOD_IN_PAST("이미 지난 시간대는 예약할 수 없습니다."),
|
||||||
|
CANCELED_BEFORE_PAYMENT("취소 시간이 결제 시간 이전일 수 없습니다."),
|
||||||
|
|
||||||
// 405 Method Not Allowed
|
// 500 Internal Server Error,
|
||||||
METHOD_NOT_ALLOWED("지원하지 않는 HTTP Method 입니다."),
|
INTERNAL_SERVER_ERROR("서버 내부에서 에러가 발생하였습니다."),
|
||||||
|
UNEXPECTED_ERROR("예상치 못한 에러가 발생하였습니다. 잠시 후 다시 시도해주세요."),
|
||||||
|
|
||||||
// 409 Conflict
|
// Payment Error
|
||||||
TIME_IS_USED_CONFLICT("삭제할 수 없는 시간대입니다. 예약이 존재하는지 확인해주세요."),
|
PAYMENT_ERROR("결제(취소)에 실패했습니다. 결제(취소) 정보를 확인해주세요."),
|
||||||
THEME_IS_USED_CONFLICT("삭제할 수 없는 테마입니다. 예약이 존재하는지 확인해주세요."),
|
PAYMENT_SERVER_ERROR("결제 서버에서 에러가 발생하였습니다. 잠시 후 다시 시도해주세요.");
|
||||||
TIME_DUPLICATED("이미 해당 시간이 존재합니다."),
|
|
||||||
THEME_DUPLICATED("같은 이름의 테마가 존재합니다."),
|
|
||||||
RESERVATION_DUPLICATED("해당 시간에 이미 예약이 존재합니다."),
|
|
||||||
RESERVATION_PERIOD_IN_PAST("이미 지난 시간대는 예약할 수 없습니다."),
|
|
||||||
CANCELED_BEFORE_PAYMENT("취소 시간이 결제 시간 이전일 수 없습니다."),
|
|
||||||
|
|
||||||
// 500 Internal Server Error,
|
companion object {
|
||||||
INTERNAL_SERVER_ERROR("서버 내부에서 에러가 발생하였습니다."),
|
@JvmStatic
|
||||||
UNEXPECTED_ERROR("예상치 못한 에러가 발생하였습니다. 잠시 후 다시 시도해주세요."),
|
@JsonCreator
|
||||||
|
fun from(@JsonProperty("errorType") errorType: String): ErrorType {
|
||||||
// Payment Error
|
return entries.toTypedArray()
|
||||||
PAYMENT_ERROR("결제(취소)에 실패했습니다. 결제(취소) 정보를 확인해주세요."),
|
.firstOrNull { it.name == errorType }
|
||||||
PAYMENT_SERVER_ERROR("결제 서버에서 에러가 발생하였습니다. 잠시 후 다시 시도해주세요.");
|
?: throw RoomEscapeException(
|
||||||
|
INVALID_REQUEST_DATA,
|
||||||
private final String description;
|
"[ErrorType: ${errorType}]",
|
||||||
|
HttpStatus.BAD_REQUEST
|
||||||
ErrorType(String description) {
|
)
|
||||||
this.description = description;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public static ErrorType from(@JsonProperty("errorType") String errorType) {
|
|
||||||
return Arrays.stream(ErrorType.values())
|
|
||||||
.filter(type -> type.name().equalsIgnoreCase(errorType))
|
|
||||||
.findFirst()
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Invalid error type: " + errorType));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ public class ExceptionControllerAdvice {
|
|||||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
public ErrorResponse handleResourceAccessException(ResourceAccessException e) {
|
public ErrorResponse handleResourceAccessException(ResourceAccessException e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
return ErrorResponse.of(ErrorType.PAYMENT_SERVER_ERROR, ErrorType.PAYMENT_SERVER_ERROR.getDescription());
|
return ErrorResponse.of(ErrorType.PAYMENT_SERVER_ERROR, ErrorType.PAYMENT_SERVER_ERROR.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = HttpMessageNotReadableException.class)
|
@ExceptionHandler(value = HttpMessageNotReadableException.class)
|
||||||
@ -41,7 +41,7 @@ public class ExceptionControllerAdvice {
|
|||||||
public ErrorResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
public ErrorResponse handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
return ErrorResponse.of(ErrorType.INVALID_REQUEST_DATA_TYPE,
|
return ErrorResponse.of(ErrorType.INVALID_REQUEST_DATA_TYPE,
|
||||||
ErrorType.INVALID_REQUEST_DATA_TYPE.getDescription());
|
ErrorType.INVALID_REQUEST_DATA_TYPE.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||||
@ -59,13 +59,13 @@ public class ExceptionControllerAdvice {
|
|||||||
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
|
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
|
||||||
public ErrorResponse handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
|
public ErrorResponse handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
return ErrorResponse.of(ErrorType.METHOD_NOT_ALLOWED, ErrorType.METHOD_NOT_ALLOWED.getDescription());
|
return ErrorResponse.of(ErrorType.METHOD_NOT_ALLOWED, ErrorType.METHOD_NOT_ALLOWED.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = Exception.class)
|
@ExceptionHandler(value = Exception.class)
|
||||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
public ErrorResponse handleException(Exception e) {
|
public ErrorResponse handleException(Exception e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
return ErrorResponse.of(ErrorType.INTERNAL_SERVER_ERROR, ErrorType.INTERNAL_SERVER_ERROR.getDescription());
|
return ErrorResponse.of(ErrorType.INTERNAL_SERVER_ERROR, ErrorType.INTERNAL_SERVER_ERROR.description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ public class RoomEscapeException extends RuntimeException {
|
|||||||
|
|
||||||
public RoomEscapeException(ErrorType errorType, String invalidValue, HttpStatusCode httpStatus) {
|
public RoomEscapeException(ErrorType errorType, String invalidValue, HttpStatusCode httpStatus) {
|
||||||
this.errorType = errorType;
|
this.errorType = errorType;
|
||||||
this.message = errorType.getDescription();
|
this.message = errorType.description;
|
||||||
this.invalidValue = invalidValue;
|
this.invalidValue = invalidValue;
|
||||||
this.httpStatus = httpStatus;
|
this.httpStatus = httpStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user