The Exceptions system provides a centralized, uniform way to handle errors across all layers and return consistent JSON responses to the client.
- Purpose: Static utility for mapping exceptions to HTTP responses.
- Handling Strategy:
- ServiceException: Maps custom business errors (e.g.,
EMPLOYEE_NOT_FOUND) to their definedErrorCode. - DecodeException: Handles JSON parsing failures (
REQ_001). - BadRequestException (v4.5): Handles OpenAPI validation errors from
RouterBuilder. ReturnsVALIDATION_ERROR. - ReplyException: Maps Event Bus failures (e.g., failed authentication from
UserVerticle→ 401 Unauthorized) to appropriate HTTP status codes. - Generic Exceptions: Catches unexpected crashes (
GEN_001) and returns 500 Internal Server Error.
- ServiceException: Maps custom business errors (e.g.,
- Response Mechanism: Uses the
ApiErrorDTO to ensure a consistent JSON structure. - Logging: Uses SLF4J to log critical failures, replacing legacy
System.errcalls.
- Purpose: A centralized registry of all possible system errors.
- Fields per Entry:
httpStatus: Standard HTTP code (e.g., 404, 429).code: Unique internal identifier (e.g.,EMP_001,SEC_001) for debugging.message: Default human-readable description.
- Purpose: Custom
RuntimeExceptionused throughout the service and repository layers. - Role: Allows logic to "fail fast" with a specific
ErrorCode, which the web layer can then easily translate for the client.
All errors follow this unified JSON format:
{
"code": "EMP_001",
"message": "Employee with the provided ID was not found.",
"timestamp": "2026-01-15T14:45:00Z"
}| Case | Exception Type | Error Code | HTTP Status |
|---|---|---|---|
| 1 | ServiceException |
From exception | From ErrorCode |
| 2 | DecodeException |
REQ_001 |
400 |
| 3 | BadRequestException (v4.5) |
VALIDATION_ERROR |
400 |
| 4 | ReplyException |
Mapped from code | Variable |
| 5 | Generic Throwable |
GEN_001 |
500 |
- Source: An error occurs in the Repository, Service, Handler, or OpenAPI validation.
- Signal: A
ServiceException(orBadRequestExceptionfrom RouterBuilder) is thrown or aFutureis failed. - Capture:
- For OpenAPI validation:
RouterBuilderthrowsBadRequestException→GlobalErrorHandlercatches. - The
Controllercatches the failure from the Event Bus and maps it back to aServiceException. - Vert.x Web
failureHandleror explicit try-catch in handlers callsGlobalErrorHandler.handle().
- For OpenAPI validation:
- Resolution:
GlobalErrorHandlerserializes theApiErrorand sends it to the client with the correct HTTP status.
When a request fails OpenAPI schema validation, RouterBuilder throws a BadRequestException. The error message contains details about which field failed validation:
{
"code": "VALIDATION_ERROR",
"message": "$.password: is missing but it is required",
"timestamp": "2026-01-29T12:00:00Z"
}