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 JSON401 Unauthorized
Invalid or missing API key. When: No auth header, invalid key format, expired token403 Forbidden
Valid auth but insufficient permissions. When: Non-admin accessing admin endpoint, user accessing another user’s job404 Not Found
Resource doesn’t exist. When: Tool not found, job doesn’t exist, server not registered429 Too Many Requests
Rate limit exceeded. When: Too many requests in short time period5xx Server Errors
500 Internal Server Error
Unexpected server error. When: Bug in API, database error, service failure504 Gateway Timeout
Tool execution exceeded timeout. When: Tool takes too long to respondError Codes Reference
Authentication Errors
| Code | HTTP | Meaning |
|---|---|---|
UNAUTHORIZED | 401 | Missing/invalid API key |
FORBIDDEN | 403 | Insufficient permissions |
INVALID_TOKEN | 401 | Token expired/revoked |
Request Errors
| Code | HTTP | Meaning |
|---|---|---|
INVALID_REQUEST | 400 | Malformed request |
INVALID_ARGUMENTS | 400 | Bad parameters |
MISSING_REQUIRED_FIELD | 400 | Missing required param |
INVALID_JSON | 400 | JSON parse error |
Resource Errors
| Code | HTTP | Meaning |
|---|---|---|
TOOL_NOT_FOUND | 404 | Tool doesn’t exist |
JOB_NOT_FOUND | 404 | Job doesn’t exist |
SERVER_NOT_FOUND | 404 | Server not found |
PACK_NOT_FOUND | 404 | Pack not found |
Execution Errors
| Code | HTTP | Meaning |
|---|---|---|
EXECUTION_ERROR | 500 | Tool failed |
EXECUTION_TIMEOUT | 504 | Tool took too long |
INVALID_ARGUMENTS | 400 | Tool params invalid |
TOOL_NOT_INSTALLED | 400 | Server not enabled |
Rate Limiting
| Code | HTTP | Meaning |
|---|---|---|
RATE_LIMITED | 429 | Too many requests |
QUOTA_EXCEEDED | 429 | Plan quota exceeded |
Server Errors
| Code | HTTP | Meaning |
|---|---|---|
INTERNAL_ERROR | 500 | Server error |
SERVICE_UNAVAILABLE | 503 | Service down |
GATEWAY_TIMEOUT | 504 | No response |
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
- 500 (Internal error) - with limit (max 3x)
- 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
- API Status: https://status.agent-corex.com
- GitHub Issues: https://github.com/ankitpro/agent-corex/issues
- Documentation: https://docs.agent-corex.com
- Email Support: support@agent-corex.com