Error Handling
How to handle errors when using Sim APIs
This guide explains how to handle errors when using Sim APIs, including common error codes, troubleshooting steps, and code examples for proper error handling.
Error Response Format
When an error occurs, Sim APIs return a standard error response format:
Common Error Codes
HTTP Status | Error Code | Description | Troubleshooting |
---|---|---|---|
401 | UNAUTHORIZED | Invalid or missing API key | Check that you’re including the correct API key in the X-Sim-Api-Key header |
400 | BAD_REQUEST | Malformed request | Verify the address format and other parameters in your request |
404 | NOT_FOUND | Resource not found | Verify the endpoint URL and resource identifiers |
429 | RATE_LIMIT_EXCEEDED | Too many requests | Implement backoff strategies and consider upgrading your plan if you consistently hit limits |
500 | INTERNAL_SERVER_ERROR | Server-side error | Retry the request after a short delay; if persistent, contact support |
Handling Errors in Code
Here are examples of how to properly handle errors in different programming languages:
JavaScript
Python
Best Practices for Error Handling
-
Always check for errors: Don’t assume API calls will succeed.
-
Implement retry logic with backoff: For transient errors (like rate limits or server errors), implement exponential backoff:
-
Provide meaningful error messages: Transform API error responses into user-friendly messages.
-
Log errors for debugging: Maintain detailed logs of API errors for troubleshooting.
-
Implement fallbacks: When possible, have fallback behavior when API calls fail.
Debugging Tips
If you’re experiencing persistent errors:
-
Verify your API key: Ensure it’s valid and has the necessary permissions.
-
Check request format: Validate that your request parameters match the API specifications.
-
Inspect full error responses: The error message often contains specific details about what went wrong.
-
Monitor your usage: Check if you’re approaching or exceeding rate limits.
-
Test with cURL: Isolate issues by testing the API directly with cURL:
Need More Help?
If you’re still experiencing issues after following these guidelines, please reach out through our support channels.