Errors vs. Warnings
Sim APIs distinguish between errors and warnings:- Errors indicate that the request failed and could not be fulfilled. The API returns an error response with an HTTP 4xx or 5xx status code.
- Warnings indicate non-fatal issues where the request was partially fulfilled. The API returns a successful HTTP 200 response with data, but includes a
warningsarray to inform you about issues that occurred.
When Warnings Occur
Warnings are currently used when you request data for specific chains via thechain_ids parameter and some of those chains are not supported. For example:
- If you request
?chain_ids=1,9999,10and chain 9999 is not supported, the API will return data for chains 1 and 10, plus a warning about chain 9999.
Warning Response Format
When warnings are present, they appear in awarnings array within the successful (HTTP 200) response:
code: A machine-readable warning code (e.g.,UNSUPPORTED_CHAIN_IDS)message: A human-readable description of the warningchain_ids: The list of chain IDs that caused this warning (for chain-related warnings)docs_url: A link to relevant documentation for more information
Error Response Format
Authentication, rate limiting, and quota enforcement errors return JSON with anerror field:
message field:
When handling errors programmatically, check for both
"error" and "message" fields in the response body.Common Error Codes
Handling Warnings in Code
When processing API responses, check for thewarnings array to be notified of non-fatal issues:
- JavaScript
- Python
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.
- 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: