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 Class | HTTP Code | Platform Code | Purpose |
|---|---|---|---|
UserNotFoundException | 404 | USER_NOT_FOUND_404 | User lookup failed. |
UserAlreadyExistsException | 409 | USER_ALREADY_EXISTS_409 | Duplicate registration attempt. |
UnAuthorizedException | 403 | ADMIN_UN_AUTHORIZED_403 | RBAC check failed. |
VaultSecretNotFoundException | 404 | VAULT_SECRET_404 | Missing secret in Vault. |
KeyCloakServiceException | 500 | KC_SERVICE_500 | Error during Keycloak API call. |
TopicCreationException | 400 | TOPIC_CREATION_FAILED_400 | Kafka 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):
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:
{
"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.