Skip to main content

Error Handling

Comprehensive guide to API errors and recovery strategies.

Response Format

All error responses follow a standard format:

HTTP Status Codes

4xx Client Errors

400 Bad Request

Invalid request format or parameters. When: Missing required fields, invalid data types, malformed JSON
Solution:

401 Unauthorized

Invalid or missing API key. When: No auth header, invalid key format, expired token
Solution:

403 Forbidden

Valid auth but insufficient permissions. When: Non-admin accessing admin endpoint, user accessing another user’s job
Solution:

404 Not Found

Resource doesn’t exist. When: Tool not found, job doesn’t exist, server not registered
Solution:

429 Too Many Requests

Rate limit exceeded. When: Too many requests in short time period
Headers:
Solution:

5xx Server Errors

500 Internal Server Error

Unexpected server error. When: Bug in API, database error, service failure
Solution:

504 Gateway Timeout

Tool execution exceeded timeout. When: Tool takes too long to respond
Solution:

Error Codes Reference

Authentication Errors

Request Errors

Resource Errors

Execution Errors

Rate Limiting

Server Errors


Error Handling Patterns

Try-Catch


Promise.catch()


With Logging


Status Code Decisions

When to Retry

Always retry:
  • 429 (Rate limited) - with exponential backoff
  • 503 (Service unavailable) - with exponential backoff
  • 504 (Timeout) - convert to job and poll
Sometimes retry:
  • 500 (Internal error) - with limit (max 3x)
Never retry:
  • 400 (Bad request) - fix parameters
  • 401 (Unauthorized) - check API key
  • 403 (Forbidden) - check permissions
  • 404 (Not found) - resource doesn’t exist

Rate Limit Recovery

Headers Check

Adaptive Rate Limiting


Common Mistakes

❌ Not Handling 429

✅ Correct - Queue with Rate Limiting


❌ Not Checking Error Code

✅ Correct - Handle by Type


Debugging Tips

Enable Request Logging

Check Request ID

Validate Before Sending


Support Resources


See Also