diff --git a/src/main/java/com/nice/petudio/global/exception/BadGatewayException.java b/src/main/java/com/nice/petudio/global/exception/BadGatewayException.java new file mode 100644 index 0000000..56362d5 --- /dev/null +++ b/src/main/java/com/nice/petudio/global/exception/BadGatewayException.java @@ -0,0 +1,10 @@ +package com.nice.petudio.global.exception; + +import com.nice.petudio.global.exception.error.ErrorCode; + +public class BadGatewayException extends CustomException { + + public BadGatewayException(ErrorCode errorCode, String message) { + super(errorCode, message); + } +} diff --git a/src/main/java/com/nice/petudio/global/exception/CustomException.java b/src/main/java/com/nice/petudio/global/exception/CustomException.java new file mode 100644 index 0000000..5dda537 --- /dev/null +++ b/src/main/java/com/nice/petudio/global/exception/CustomException.java @@ -0,0 +1,14 @@ +package com.nice.petudio.global.exception; + +import com.nice.petudio.global.exception.error.ErrorCode; +import lombok.Getter; + +@Getter +public class CustomException extends RuntimeException { + private final ErrorCode errorCode; + + public CustomException(ErrorCode errorCode, String message) { + super(message); + this.errorCode = errorCode; + } +} diff --git a/src/main/java/com/nice/petudio/global/exception/ForbiddenException.java b/src/main/java/com/nice/petudio/global/exception/ForbiddenException.java new file mode 100644 index 0000000..f0c03b0 --- /dev/null +++ b/src/main/java/com/nice/petudio/global/exception/ForbiddenException.java @@ -0,0 +1,10 @@ +package com.nice.petudio.global.exception; + +import com.nice.petudio.global.exception.error.ErrorCode; + +public class ForbiddenException extends CustomException { + + public ForbiddenException(ErrorCode errorCode, String message) { + super(errorCode, message); + } +} diff --git a/src/main/java/com/nice/petudio/global/exception/InternalServerException.java b/src/main/java/com/nice/petudio/global/exception/InternalServerException.java new file mode 100644 index 0000000..47ca6e8 --- /dev/null +++ b/src/main/java/com/nice/petudio/global/exception/InternalServerException.java @@ -0,0 +1,10 @@ +package com.nice.petudio.global.exception; + +import com.nice.petudio.global.exception.error.ErrorCode; + +public class InternalServerException extends CustomException { + + public InternalServerException(ErrorCode errorCode, String message) { + super(errorCode, message); + } +} diff --git a/src/main/java/com/nice/petudio/global/exception/NotFoundException.java b/src/main/java/com/nice/petudio/global/exception/NotFoundException.java new file mode 100644 index 0000000..d378f28 --- /dev/null +++ b/src/main/java/com/nice/petudio/global/exception/NotFoundException.java @@ -0,0 +1,10 @@ +package com.nice.petudio.global.exception; + +import com.nice.petudio.global.exception.error.ErrorCode; + +public class NotFoundException extends CustomException { + + public NotFoundException(ErrorCode errorCode, String message) { + super(errorCode, message); + } +} diff --git a/src/main/java/com/nice/petudio/global/exception/UnauthorizedException.java b/src/main/java/com/nice/petudio/global/exception/UnauthorizedException.java new file mode 100644 index 0000000..d21e5fe --- /dev/null +++ b/src/main/java/com/nice/petudio/global/exception/UnauthorizedException.java @@ -0,0 +1,10 @@ +package com.nice.petudio.global.exception; + +import com.nice.petudio.global.exception.error.ErrorCode; + +public class UnauthorizedException extends CustomException { + + public UnauthorizedException(ErrorCode errorCode, String message) { + super(errorCode, message); + } +} diff --git a/src/main/java/com/nice/petudio/global/exception/ValidationException.java b/src/main/java/com/nice/petudio/global/exception/ValidationException.java new file mode 100644 index 0000000..45d46bf --- /dev/null +++ b/src/main/java/com/nice/petudio/global/exception/ValidationException.java @@ -0,0 +1,10 @@ +package com.nice.petudio.global.exception; + +import com.nice.petudio.global.exception.error.ErrorCode; + +public class ValidationException extends CustomException { + + public ValidationException(ErrorCode errorCode, String message) { + super(errorCode, message); + } +} diff --git a/src/main/java/com/nice/petudio/global/exception/error/ErrorCode.java b/src/main/java/com/nice/petudio/global/exception/error/ErrorCode.java new file mode 100644 index 0000000..770d195 --- /dev/null +++ b/src/main/java/com/nice/petudio/global/exception/error/ErrorCode.java @@ -0,0 +1,37 @@ +package com.nice.petudio.global.exception.error; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum ErrorCode { + // Validation Exception + VALIDATION_EXCEPTION("V001", "잘못된 요청입니다."), + METHOD_NOT_ALLOWED_EXCEPTION("V002", "지원하지 않는 메소드입니다."), + UNSUPPORTED_MEDIA_TYPE("V003", "허용하지 않는 미디어 타입입니다."), + INVALID_TOKEN_EXCEPTION("V004", "잘못된 JWT 토큰 형식입니다."), + + // Unauthorized Exception + UNAUTHORIZED_TOKEN_EXCEPTION("U001", "토큰이 존재하지 않거나 유효하지 않습니다. 다시 로그인 해주세요."), + + // Forbidden Exception + FORBIDDEN_EXCEPTION("F001", "접근 권한이 존재하지 않습니다."), + + // NotFound Exception + NOT_FOUND_EXCEPTION("N001", "존재하지 않는 요청입니다."), + NOT_FOUND_MEMBER_EXCEPTION("N002", "탈퇴했거나 존재하지 않는 회원입니다."), + NOT_FOUND_CONCEPT_EXCEPTION("N004", "존재하지 않는 컨셉입니다."), + + // Conflict Exception + CONFLICT_EXCEPTION("C001", "이미 존재하는 데이터입니다."), + CONFLICT_MEMBER_EXCEPTION("C002", "이미 해당 계정으로 회원가입이 되어있습니다.\n로그인 해주세요."), + + // Internal Server Exception + INTERNAL_SERVER_EXCEPTION("I001", "서버 내부에서 에러가 발생하였습니다."), + + // Bad Gateway Exception + BAD_GATEWAY_EXCEPTION("B001", "외부 연동 중 에러가 발생하였습니다."); + + + private final String code; + private final String message; +}