Prerequisites
- SDK installed and configured (see SDK Quickstart)
Error types
HTTP errors
The SDK throws errors for HTTP response codes indicating failures:| Status | Name | Description |
|---|---|---|
| 400 | Bad Request | Invalid request parameters or malformed query |
| 401 | Unauthorized | Invalid or missing API key |
| 403 | Forbidden | API key lacks required permissions |
| 404 | Not Found | Resource doesn’t exist |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Server-side error |
| 502 | Bad Gateway | Upstream service error |
| 503 | Service Unavailable | Service temporarily unavailable |
Network errors
Connection issues throw standard JavaScript errors:- Connection timeout
- DNS resolution failure
- Network unreachable
Validation errors
Query or data validation failures return detailed error messages:- NQL syntax errors
- Schema validation failures
- Invalid parameter values
Basic error handling
Wrap SDK calls in try-catch blocks:Handling specific errors
Check the error status for specific handling:Rate limiting
Handle rate limits with exponential backoff:Query error handling
NQL queries can fail for various reasons:Validating before execution
Catch syntax errors before running expensive queries:Creating an error wrapper
Build a reusable error handler:Logging errors
Implement structured error logging:Graceful degradation
Provide fallbacks when services are unavailable:Best practices
| Practice | Description |
|---|---|
| Always use try-catch | Wrap all SDK calls in error handlers |
| Check error status | Handle different errors appropriately |
| Implement retries | Use exponential backoff for transient errors |
| Validate inputs | Catch errors early with validation |
| Log errors | Record errors for debugging and monitoring |
| Graceful degradation | Provide fallbacks when possible |
Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Frequent 401 errors | API key expired or invalid | Generate a new API key |
| Frequent 429 errors | Too many requests | Implement rate limiting and backoff |
| Intermittent 500 errors | Server issues | Implement retry logic |
| Network timeouts | Slow connection or large responses | Increase timeout or paginate |

