Guides

Error Handling

The Prepzo API uses consistent error formats across all endpoints. Every response tells you exactly what went wrong and how to fix it.

Response Format

All API responses follow the same structure:

// Success
{
  "success": true,
  "data": { ... },
  "meta": { "total": 50, "limit": 50, "offset": 0, "has_more": false },
  "errors": null
}

// Error
{
  "success": false,
  "data": null,
  "meta": null,
  "errors": [
    {
      "code": "not_found",
      "message": "Candidate not found",
      "field": null
    }
  ]
}

HTTP Status Codes

CodeMeaning
200Success
201Created successfully
401Unauthorized - missing or invalid API key
403Forbidden - API key lacks required scope
404Not found - resource doesn't exist
409Conflict - duplicate resource
422Validation error - missing or invalid fields
429Rate limited - too many requests
500Server error - something went wrong on our end

Error Codes

CodeDescription
unauthorizedAPI key is missing or invalid
forbiddenInsufficient permissions for this endpoint
not_foundThe requested resource was not found
duplicateResource already exists (unique constraint)
validation_errorRequest body failed validation
rate_limitedRate limit exceeded
server_errorInternal server error

Validation Errors

Validation errors include a field property pointing to the problematic field:

{
  "success": false,
  "data": null,
  "errors": [
    {
      "code": "validation_error",
      "message": "email is required",
      "field": "email"
    }
  ]
}

Best Practices

  • Always check success: Don't rely solely on HTTP status codes
  • Handle 429s gracefully: Implement exponential backoff with the Retry-After header
  • Log error codes: The code field is stable and safe for programmatic handling
  • Don't parse messages: The message field is human-readable and may change
  • Retry 500s: Server errors are typically transient. Retry with backoff.
  • Don't retry 4xx: Client errors (except 429) won't succeed on retry without changes