Exception Framework

Global error handling and exception hierarchy in Arya Banking.

Centralized Error Handling

Arya Banking uses a unified exception hierarchy defined in the core module of arya-banking-common and applied via @RestControllerAdvice in every microservice.


1. Global Exception Class

The GlobalException class is the root of all domain-specific errors. It carries:

  • httpErrorCode: The standard HTTP status code (e.g., 404, 401).
  • errorCode: A platform-specific error code (e.g., USER_NOT_FOUND_404).
  • errorMessage: A human-readable message.

2. Error Mapping Matrix

Exception ClassHTTP CodePlatform CodePurpose
UserNotFoundException404USER_NOT_FOUND_404User lookup failed.
UserAlreadyExistsException409USER_ALREADY_EXISTS_409Duplicate registration attempt.
UnAuthorizedException403ADMIN_UN_AUTHORIZED_403RBAC check failed.
VaultSecretNotFoundException404VAULT_SECRET_404Missing secret in Vault.
KeyCloakServiceException500KC_SERVICE_500Error during Keycloak API call.
TopicCreationException400TOPIC_CREATION_FAILED_400Kafka Admin createTopics failed (admin-service, core:2.0.2+).

ResponseDto (core 2.0.2+)

Generic success envelope used by admin operations that return no domain object (e.g. Kafka topic creation):

> Java code-highlight
public record ResponseDto(String responseCode, String message) {}
// e.g. new ResponseDto("200", "Topic created successfully")

3. Global Exception Handler

The GlobalExceptionHandler is automatically picked up via @ComponentScan("org.arya.banking.common.core"). It intercepts all thrown GlobalException subclasses and returns a consistent JSON payload:

> Json code-highlight
{
  "errorCode": "USER_NOT_FOUND_404",
  "errorMessage": "User not found with ID: ARYA123456"
}

4. Feign Error Decoding

Inter-service communication errors are deserialized back into their original exception types via the FeignClientErrorDecoder (in the feign module). This ensures that a 404 from the auth-service is correctly re-thrown as a UserNotFoundException in the user-service.

This pattern maintains a clean, uniform error experience across the entire distributed system.