diff --git a/src/main/java/com/runtimematrix/domain/exception/BusinessException.java b/src/main/java/com/runtimematrix/domain/exception/BusinessException.java new file mode 100644 index 0000000..78fe91b --- /dev/null +++ b/src/main/java/com/runtimematrix/domain/exception/BusinessException.java @@ -0,0 +1,42 @@ +package com.runtimematrix.domain.exception; + +import java.text.MessageFormat; + +/** + * 비즈니스 로직 수행 중 발생하는 예외의 기본 클래스. + * 모든 도메인 예외는 이 클래스를 상속한다. + */ +public abstract class BusinessException extends RuntimeException { + + private final String errorCode; + private final String resourceId; + + protected BusinessException(String errorCode, String message, String resourceId) { + super(message); + this.errorCode = errorCode; + this.resourceId = resourceId; + } + + public String getErrorCode() { return errorCode; } + public String getResourceId() { return resourceId; } + public abstract int getHttpStatus(); + public String getType() { return "https://api.runtimematrix.com/errors/" + errorCode; } + + /** 역할 미존재 예외 */ + public static class RoleNotFoundException extends BusinessException { + private static final String CODE = "role-not-found"; + public RoleNotFoundException(String roleId) { + super(CODE, MessageFormat.format("ID가 ''{0}''인 역할을 찾을 수 없습니다.", roleId), roleId); + } + @Override public int getHttpStatus() { return 404; } + } + + /** 역할 중복 예외 */ + public static class RoleAlreadyExistsException extends BusinessException { + private static final String CODE = "role-already-exists"; + public RoleAlreadyExistsException(String roleName) { + super(CODE, MessageFormat.format("이름이 ''{0}''인 역할이 이미 존재합니다.", roleName), roleName); + } + @Override public int getHttpStatus() { return 409; } + } +}