Skip to main content

Error Handling

All API endpoints follow a consistent error handling pattern. When an error occurs, the response will include:

Response Structure

{
"code": "ERROR_CODE",
"timestamp": "2025-07-29T10:00:00.000Z",
"path": "/api/resource",
"description": "Human readable error description"
}
FieldTypeDescription
codestringA unique error code identifying the type of error
timestampstringISO 8601 timestamp when the error occurred
pathstringThe API endpoint path where the error occurred
descriptionstringA human-readable description of the error

Standard HTTP Status Codes

Status CodeDescription
400Bad Request - The request was malformed or contained invalid parameters
401Unauthorized - Authentication is required or the provided credentials are invalid
403Forbidden - The authenticated user doesn't have permission to access the requested resource
404Not Found - The requested resource does not exist
404Invalid State - Cannot { HTTP method } { resource path }
409Conflict - The request conflicts with the current state of the server
422Unprocessable Entity - The request was well-formed but contains semantic errors
429Too Many Requests - Rate limit has been exceeded
500Internal Server Error - An unexpected error occurred on the server
502Bad Gateway - Invalid response from an upstream server

Common Error Codes

CodeDescriptionHTTP Status
UNKNOWN_ERRORInternal server error500
GENERAL_ERRORA general error occurred500
UNAUTHORIZEDAuthentication failed or token expired401
BAD_REQUESTInvalid request parameters400
NOT_FOUNDResource not found404
FORBIDDENInsufficient permissions403
CONFLICTResource conflict409
INVALID_STATEResource not found404
UNPROCESSABLEValidation failed422

Example Error Responses

Authentication Error (401 Unauthorized)

{
"code": "UNAUTHORIZED",
"timestamp": "2025-07-29T10:00:00.000Z",
"path": "/api/v1/users",
"description": "Token invalid or expired"
}

Validation Error (400 Bad Request)

{
"code": "BAD_REQUEST",
"timestamp": "2025-07-29T10:00:00.000Z",
"path": "/api/v1/users",
"description": "Invalid input parameters"
}

Resource Not Found (404 Not Found)

{
"code": "NOT_FOUND",
"timestamp": "2025-07-29T10:00:00.000Z",
"path": "/api/v1/users/123",
"description": "User not found"
}

Permission Error (403 Forbidden)

{
"code": "FORBIDDEN",
"timestamp": "2025-07-29T10:00:00.000Z",
"path": "/api/v1/admin/settings",
"description": "Insufficient permissions to access this resource"
}

Conflict Error (409 Conflict)

{
"code": "CONFLICT",
"timestamp": "2025-07-29T10:00:00.000Z",
"path": "/api/v1/users",
"description": "User with this email already exists"
}

Resource Not Found (404 Invalid State)

{
"code": "INVALID_STATE",
"timestamp": "2025-07-29T10:00:00.000Z",
"path": "/api/v1/users/550e8400-e29b-41d4-a716-446655440000/activate",
"description": "Cannot PATCH /api/v1/users/550e8400-e29b-41d4-a716-446655440000/activate"
}