Error Response Protocol

The API implements a standardized error response schema:
interface ErrorResponse {
  status: number;      // HTTP status code
  message: string;     // Human-readable description
  error_code: string;  // Machine-parseable identifier
}

Error Classification Hierarchy

Database Operation Failures (500)

MongoDB operation exception handling:
{
  "status": 500,
  "message": "Database operation failed: write concern error",
  "error_code": "DATABASE_ERROR"
}

Resource Resolution Failures (404)

Entity resolution exception handling:
{
  "status": 404,
  "message": "Resource not found in collection",
  "error_code": "NOT_FOUND"
}

Request Validation Failures (400)

Schema validation exception handling:
{
  "status": 400,
  "message": "Invalid input: constraint violation",
  "error_code": "INVALID_INPUT"
}

System-Level Failures (500)

Runtime exception handling:
{
  "status": 500,
  "message": "Internal error: system constraint violation",
  "error_code": "INTERNAL_ERROR"
}

Rate Limit Exceptions (429)

Throughput constraint violations:
{
  "status": 429,
  "message": "Rate limit exceeded: throughput constraint violation",
  "error_code": "RATE_LIMIT_EXCEEDED"
}

Exception Handling Implementation

Best Practices

  1. Implement status code validation
  2. Parse error_code enum values
  3. Log message content for debugging
  4. Implement exponential backoff for 429
  5. Handle 500-level errors with circuit breaking