diff --git a/src/main/java/com/klaroworks/runtime/exception/BaseException.java b/src/main/java/com/klaroworks/runtime/exception/BaseException.java new file mode 100644 index 0000000..f7202af --- /dev/null +++ b/src/main/java/com/klaroworks/runtime/exception/BaseException.java @@ -0,0 +1,34 @@ +package com.klaroworks.runtime.exception; + +public abstract class BaseException extends RuntimeException { + private final ErrorCode errorCode; + + protected BaseException(ErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } + + protected BaseException(ErrorCode errorCode, String message) { + super(message); + this.errorCode = errorCode; + } + + public ErrorCode getErrorCode() { return errorCode; } +} + +class BusinessException extends BaseException { + public BusinessException(ErrorCode errorCode) { super(errorCode); } + public BusinessException(ErrorCode errorCode, String message) { super(errorCode, message); } +} + +class RoleNotFoundException extends BusinessException { + public RoleNotFoundException(Long roleId) { + super(ErrorCode.ROLE_NOT_FOUND, String.format("Role not found with id: %d", roleId)); + } +} + +class DuplicateResourceException extends BusinessException { + public DuplicateResourceException(String resourceType, String identifier) { + super(ErrorCode.DUPLICATE_ROLE_NAME, String.format("%s '%s' already exists", resourceType, identifier)); + } +}