OpenGraph.io

Error Handling

Learn how to handle API errors gracefully and troubleshoot common issues.

HTTP Status Codes

CodeMeaningAction
200SuccessRequest completed successfully
400Bad RequestCheck URL encoding and parameters
401UnauthorizedCheck your App ID
403ForbiddenTarget site blocked the request; try proxies
404Not FoundTarget URL doesn't exist
429Too Many RequestsRate limited; implement backoff
500Server ErrorRetry the request
502/503Gateway ErrorTarget site unavailable; retry later

Error Response Format

Error responses include details about what went wrong:

Error response
{
  "error": true,
  "message": "Invalid App ID",
  "code": "INVALID_APP_ID"
}

Common Errors and Solutions

Invalid App ID (401)

Your App ID is missing or incorrect.

  • Verify your App ID in the dashboard
  • Ensure the parameter is named app_id
  • Check for typos or extra spaces

URL Encoding Issues (400)

The target URL wasn't properly encoded.

  • Use encodeURIComponent() in JavaScript
  • Use urllib.parse.quote() with safe='' in Python
  • See URL Encoding guide

Target Site Blocked (403)

The target website blocked the request.

  • Try adding use_proxy=true
  • For Cloudflare sites, try use_premium=true
  • For heavily protected sites, try use_superior=true
  • See Proxy Options

Rate Limited (429)

Too many concurrent requests.

  • Implement exponential backoff
  • Queue requests to stay within limits
  • Consider upgrading your plan
  • See Rate Limits

Target Site Unavailable (502/503)

The target website is down or unresponsive.

  • Wait and retry the request
  • Check if the target site is actually online
  • Try full_render=true for slow sites

Implementing Error Handling

async function fetchOpenGraph(targetUrl) {
  const encodedUrl = encodeURIComponent(targetUrl);
  const apiUrl = `https://opengraph.io/api/1.1/site/${encodedUrl}?app_id=${process.env.APP_ID}`;
  
  const response = await fetch(apiUrl);
  
  if (!response.ok) {
    switch (response.status) {
      case 401:
        throw new Error('Invalid App ID');
      case 403:
        // Retry with proxy
        return fetchWithProxy(targetUrl);
      case 429:
        // Wait and retry
        await sleep(1000);
        return fetchOpenGraph(targetUrl);
      case 404:
        throw new Error('Target URL not found');
      default:
        throw new Error(`API error: ${response.status}`);
    }
  }
  
  return response.json();
}

Related