Skip to main content
This guide explains how to handle errors when using Sim APIs, including common error codes, troubleshooting steps, and code examples for proper error handling.

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 warnings array to inform you about issues that occurred.

When Warnings Occur

Warnings are currently used when you request data for specific chains via the chain_ids parameter and some of those chains are not supported. For example:
  • If you request ?chain_ids=1,9999,10 and 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 a warnings array within the successful (HTTP 200) response:
{
  "wallet_address": "0x37305b1cd40574e4c5ce33f8e8306be057fd7341",
  "balances": [...],
  "warnings": [
    {
      "code": "UNSUPPORTED_CHAIN_IDS",
      "message": "Some requested chain_ids are not supported. Balances are returned only for supported chains.",
      "chain_ids": [9999, 77777777777],
      "docs_url": "https://docs.sim.dune.com/evm/supported-chains"
    }
  ]
}
Each warning includes:
  • code: A machine-readable warning code (e.g., UNSUPPORTED_CHAIN_IDS)
  • message: A human-readable description of the warning
  • chain_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

When an error occurs, Sim APIs return a JSON response with error information:
{
  "error": "Description of what went wrong"
}
The error property can be either "error" or "message" depending on the type of error.

Common Error Codes

HTTP StatusDescriptionTroubleshooting
401Invalid or missing API keyCheck that you’re including the correct API key in the X-Sim-Api-Key header
400Malformed requestVerify the address format and other parameters in your request
402Compute units quota exceededYou are out of compute units. Please contact sales to upgrade your plan: [email protected]
404Resource not foundVerify the endpoint URL and resource identifiers
429Too many requestsImplement backoff strategies and consider upgrading your plan if you consistently hit limits
500Server-side errorRetry the request after a short delay; if persistent, contact support

Handling Warnings in Code

When processing API responses, check for the warnings array to be notified of non-fatal issues:
const response = await fetch('https://api.sim.dune.com/v1/evm/balances/0xd8da6bf26964af9d7eed9e03e53415d37aa96045?chain_ids=1,9999,10', {
  headers: {'X-Sim-Api-Key': 'YOUR_API_KEY'}
});

const data = await response.json();

// Check for warnings
if (data.warnings && data.warnings.length > 0) {
  data.warnings.forEach(warning => {
    if (warning.code === 'UNSUPPORTED_CHAIN_IDS') {
      console.warn(`Warning: Chains ${warning.chain_ids.join(', ')} are not supported.`);
      console.warn(`See: ${warning.docs_url}`);
    }
  });
}

// Process the data that was successfully returned
console.log(`Found ${data.balances.length} balances`);

Handling Errors in Code

Here are examples of how to properly handle errors in different programming languages:
fetch('https://api.sim.dune.com/v1/evm/balances/0xd8da6bf26964af9d7eed9e03e53415d37aa96045', {
  method: 'GET', 
  headers: {'X-Sim-Api-Key': 'YOUR_API_KEY'}
})
  .then(response => {
    if (!response.ok) {
      return response.json().then(err => {
        const errorMessage = err.error || err.message || response.statusText;
        throw new Error(`API error: ${errorMessage}`);
      });
    }
    return response.json();
  })
  .then(data => {
    console.log('Success:', data);
    // Process your data here
  })
  .catch(err => {
    console.error('Error fetching balances:', err);
    // Handle error appropriately in your application
    // e.g., show user-friendly message, retry, or fallback behavior
  });

Best Practices for Error Handling

  1. Always check for errors: Don’t assume API calls will succeed.
  2. Use HTTP status codes: Rely on HTTP status codes rather than parsing error message strings for programmatic decisions.
  3. Implement retry logic with backoff: For transient errors (like rate limits or server errors), implement exponential backoff.
  4. Provide meaningful error messages: Transform API error responses into user-friendly messages.
  5. Log errors for debugging: Maintain detailed logs of API errors for troubleshooting.
  6. Implement fallbacks: When possible, have fallback behavior when API calls fail.

Debugging Tips

If you’re experiencing persistent errors:
  1. Verify your API key: Ensure it’s valid and has the necessary permissions.
  2. Check request format: Validate that your request parameters match the API specifications.
  3. Inspect full error responses: The error message often contains specific details about what went wrong.
  4. Monitor your usage: Check if you’re approaching or exceeding rate limits.
  5. Test with cURL: Isolate issues by testing the API directly with cURL:
    curl -v -X GET "https://api.sim.dune.com/v1/evm/balances/0xd8da6bf26964af9d7eed9e03e53415d37aa96045" \
         -H "X-Sim-Api-Key: YOUR_API_KEY"
    

Need More Help?

If you’re still experiencing issues after following these guidelines, please reach out through our support channels.