Error Response Format
When an error occurs, Sim APIs return a JSON response with error information:The error property can be either
"error"
or "message"
depending on the type of error.Common Error Codes
HTTP Status | Description | Troubleshooting |
---|---|---|
401 | Invalid or missing API key | Check that you’re including the correct API key in the X-Sim-Api-Key header |
400 | Malformed request | Verify the address format and other parameters in your request |
404 | Resource not found | Verify the endpoint URL and resource identifiers |
429 | Too many requests | Implement backoff strategies and consider upgrading your plan if you consistently hit limits |
500 | 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:Best Practices for Error Handling
- Always check for errors: Don’t assume API calls will succeed.
- Use HTTP status codes: Rely on HTTP status codes rather than parsing error message strings for programmatic decisions.
- 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: