Error Handling
Learn how to handle API errors gracefully and troubleshoot common issues.
HTTP Status Codes
| Code | Meaning | Action |
|---|---|---|
| 200 | Success | Request completed successfully |
| 400 | Bad Request | Check URL encoding and parameters |
| 401 | Unauthorized | Check your App ID |
| 403 | Forbidden | Target site blocked the request; try proxies |
| 404 | Not Found | Target URL doesn't exist |
| 429 | Too Many Requests | Rate limited; implement backoff |
| 500 | Server Error | Retry the request |
| 502/503 | Gateway Error | Target 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()withsafe=''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=truefor 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();
}