How to Handle Errors

Learn how to handle API errors robustly.

Problem

You want your application to handle errors gracefully without breaking the user experience.

Solution

Implement error handling at 3 levels: validation, HTTP response, and retry.

1. Validation Before Sending

Avoid errors by validating data first:

function validateRequest(query, tenantId) {
  if (!query || query.trim() === '') {
    throw new Error('Query is required');
  }

  if (!tenantId) {
    throw new Error('tenant_id is required');
  }

  return true;
}

2. HTTP Code Handling

3. Custom Error Classes

4. Retry with Exponential Backoff

For temporary errors (429, 500, 503):

5. Complete Usage

Python: Error Handling

Common Errors and Solutions

Error
Cause
Solution

tenant_id is required

Missing tenant_id

Add tenant_id to filters

query is required

Empty query

Validate before sending

Rate limit exceeded

Too many requests

Implement retry with backoff

Internal server error

Server error

Automatic retry

Service unavailable

Maintenance

Wait and try again

Error Logging

Last updated

Was this helpful?