Skip to main content

Error Handling

All Scrapebit API errors follow a consistent format to help you handle them effectively.

Error Response Format

{
"success": false,
"error": {
"code": "error_code",
"message": "Human-readable error message",
"details": {}
}
}

HTTP Status Codes

CodeDescription
400Bad Request - Invalid parameters
401Unauthorized - Invalid or missing API key
403Forbidden - Insufficient permissions or credits
404Not Found - Resource doesn't exist
429Too Many Requests - Rate limit exceeded
500Internal Server Error - Something went wrong
503Service Unavailable - Temporary outage

Common Error Codes

Authentication Errors

CodeMessageSolution
unauthorizedInvalid or missing API keyCheck your API key is correct
api_key_expiredAPI key has been regeneratedUse your new API key
api_key_revokedAPI key has been revokedGenerate a new API key

Validation Errors

CodeMessageSolution
invalid_urlThe provided URL is not validCheck URL format
invalid_parameterInvalid parameter valueCheck parameter requirements
missing_parameterRequired parameter missingInclude all required fields
url_not_accessibleCannot access the URLVerify URL is publicly accessible

Credit Errors

CodeMessageSolution
insufficient_creditsNot enough creditsPurchase more credits
credits_expiredYour credits have expiredPurchase new credits

Rate Limit Errors

CodeMessageSolution
rate_limit_exceededToo many requestsSlow down and retry later
concurrent_limit_exceededToo many concurrent requestsWait for current requests to complete

Resource Errors

CodeMessageSolution
not_foundResource not foundCheck the resource ID
already_existsResource already existsUse a different identifier
already_deletedResource has been deletedCannot operate on deleted resource

Processing Errors

CodeMessageSolution
timeoutRequest timed outIncrease timeout or simplify request
blockedAccess was blockedTry with proxy enabled
page_too_largeContent exceeds size limitScrape smaller sections
extraction_failedAI extraction failedRefine your extraction prompt

Error Handling Examples

JavaScript

import { Scrapebit, ScrapebitError } from '@scrapebit/sdk';

const client = new Scrapebit('YOUR_API_KEY');

try {
const result = await client.content.scrape({ url: 'https://example.com' });
} catch (error) {
if (error instanceof ScrapebitError) {
switch (error.code) {
case 'unauthorized':
console.error('Invalid API key');
break;
case 'insufficient_credits':
console.error('Need more credits');
// Redirect to purchase page
break;
case 'rate_limit_exceeded':
console.error(`Rate limited. Retry in ${error.retryAfter}s`);
await sleep(error.retryAfter * 1000);
// Retry request
break;
case 'timeout':
console.error('Request timed out');
// Retry with longer timeout
break;
default:
console.error(`Error: ${error.message}`);
}
}
}

Python

from scrapebit import Scrapebit, ScrapebitError

client = Scrapebit(api_key="YOUR_API_KEY")

try:
result = client.content.scrape(url="https://example.com")
except ScrapebitError as e:
if e.code == "unauthorized":
print("Invalid API key")
elif e.code == "insufficient_credits":
print("Need more credits")
elif e.code == "rate_limit_exceeded":
print(f"Rate limited. Retry in {e.retry_after}s")
time.sleep(e.retry_after)
# Retry request
elif e.code == "timeout":
print("Request timed out")
else:
print(f"Error: {e.message}")

cURL

response=$(curl -s -w "\n%{http_code}" -X POST https://api.scrapebit.com/v1/content/scrape \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}')

http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | head -n -1)

if [ "$http_code" != "200" ]; then
error_code=$(echo "$body" | jq -r '.error.code')
echo "Error: $error_code"
fi

Retry Strategy

For transient errors, implement a retry strategy:

async function withRetry(fn, maxRetries = 3) {
const retryableErrors = ['timeout', 'rate_limit_exceeded', 'service_unavailable'];

for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await fn();
} catch (error) {
if (!retryableErrors.includes(error.code) || attempt === maxRetries) {
throw error;
}

const delay = Math.min(1000 * Math.pow(2, attempt), 30000);
await new Promise(r => setTimeout(r, delay));
}
}
}

Getting Help

If you encounter persistent errors:

  1. Check the API Status Page
  2. Review your request parameters
  3. Contact support@scrapebit.com with:
    • The error code and message
    • Your request details (without API key)
    • Timestamp of the error