Skip to main content

Error Handling & Standardized Response Flow

Global pipeline for intercepting failures, mapping them to business-friendly status codes, and ensuring diagnostic traceability.

Sequence​

Error Mapping Strategy​

The system uses a centralized mapping logic to ensure consistency across all endpoints:

Exception TypeHTTP StatusBusiness Error Code
UserFriendlyExceptionDynamic (Mapped)Dynamic (Mapped)
KeyNotFoundException404 Not FoundIA.NOT_FOUND
ValidationException400 Bad RequestIA.BAD_REQUEST
UnauthorizedAccessException401 UnauthorizedIA.UNAUTHORIZED
System.Exception500 Internal ErrorIA.GENERAL_ERROR

Response Structure​

All errors follow the same JSON schema to allow the frontend to display uniform error alerts:

{
"error": {
"code": "InventoryAlert.NOT_FOUND",
"message": "Symbol 'XYZ' is not recognized."
},
"correlationId": "CID-123",
"timestamp": "2026-05-04T12:00:00Z"
}

Logic Highlights​

FeatureDetail
Diagnostic TraceEvery error response includes the correlationId, allowing users to provide a reference for support logs.
User Friendly MessagesUserFriendlyException allows services to pass safe, translated messages to the UI while keeping technical details in logs.
Validation IntegrationAutomatically captures and formats FluentValidation failures into the standard error schema.
Transaction RollbackSince the middleware catches exceptions at the top level, incomplete DB transactions are naturally rolled back by the Unit of Work.