Skip to content

Commit

Permalink
feat: Custom Exception 구현 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Jan 18, 2024
1 parent 671821a commit 5ee28f7
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 5ee28f7

Please sign in to comment.