Social Scraper

Error Handling

Understanding API error responses and status codes.

Error Handling

The Social Scraper API uses conventional HTTP response codes to indicate the success or failure of an API request.

HTTP Status Codes

CodeStatusDescription
200OKThe request was successful
400Bad RequestThe request was malformed or missing required parameters
401UnauthorizedInvalid or missing API key
403ForbiddenThe API key doesn't have permission for this resource
404Not FoundThe requested profile or resource doesn't exist
429Too Many RequestsRate limit exceeded
500Internal Server ErrorSomething went wrong on our end

Error Response Format

All error responses follow a consistent JSON structure:

{
  "error": "error_code",
  "message": "Human-readable error description"
}

Common Errors

Invalid Username

Returned when the username format is invalid or contains unsupported characters.

{
  "error": "bad_request",
  "message": "Invalid username format"
}

Status Code: 400 Bad Request

Profile Not Found

Returned when the requested profile doesn't exist or is not publicly accessible.

{
  "error": "not_found",
  "message": "Profile not found"
}

Status Code: 404 Not Found

Rate Limit Exceeded

Returned when you've made too many requests in a given time period.

{
  "error": "rate_limited",
  "message": "Too many requests. Please retry after 60 seconds."
}

Status Code: 429 Too Many Requests

Rate limit headers are included in every response to help you track your usage.

Rate Limit Headers

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per window
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetUnix timestamp when the rate limit resets

Profile Extraction Failed

Returned when the API was unable to extract profile data from the platform.

{
  "error": "extraction_failed",
  "message": "Failed to extract profile data from page"
}

Status Code: 500 Internal Server Error

Handling Errors in Code

JavaScript

async function getProfile(platform, username) {
  const response = await fetch(
    `https://api.your-domain.com/${platform}/profile/${username}`,
    {
      headers: {
        'Authorization': `Bearer ${apiKey}`
      }
    }
  );

  if (!response.ok) {
    const error = await response.json();
    
    switch (response.status) {
      case 401:
        throw new Error('Invalid API key');
      case 404:
        throw new Error(`Profile "${username}" not found`);
      case 429:
        throw new Error('Rate limit exceeded, please retry later');
      default:
        throw new Error(error.message || 'An error occurred');
    }
  }

  return response.json();
}

Python

import requests

def get_profile(platform, username):
    response = requests.get(
        f'https://api.your-domain.com/{platform}/profile/{username}',
        headers={'Authorization': f'Bearer {api_key}'}
    )
    
    if response.status_code == 401:
        raise Exception('Invalid API key')
    elif response.status_code == 404:
        raise Exception(f'Profile "{username}" not found')
    elif response.status_code == 429:
        raise Exception('Rate limit exceeded, please retry later')
    elif not response.ok:
        error = response.json()
        raise Exception(error.get('message', 'An error occurred'))
    
    return response.json()

Best Practices

  1. Always check status codes - Don't assume every response is successful
  2. Implement retry logic - For rate limits (429) and server errors (5xx)
  3. Log errors - Keep track of errors for debugging
  4. Handle gracefully - Provide meaningful feedback to your users

On this page