Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Codes

StyleGrab API returns structured error responses with machine-readable codes.

Error Response Format

{
  "error": {
    "code": "not_found",
    "message": "Extraction not found",
    "details": {}
  }
}

Authentication Errors

CodeHTTP StatusDescription
unauthorized401Missing or invalid authentication
token_expired401JWT token has expired
invalid_api_key401API key is invalid or revoked
forbidden403Valid auth but insufficient permissions

Validation Errors

CodeHTTP StatusDescription
validation_error422Request body failed validation
invalid_url400URL is malformed or unreachable
invalid_webhook_url400Webhook URL must be HTTPS
missing_field400Required field not provided

Example:

{
  "error": {
    "code": "validation_error",
    "message": "Validation failed",
    "details": {
      "fields": {
        "url": "must be a valid URL",
        "events": "must include at least one event"
      }
    }
  }
}

Resource Errors

CodeHTTP StatusDescription
not_found404Resource does not exist
already_exists409Resource already exists
conflict409Operation conflicts with current state

Extraction Errors

CodeHTTP StatusDescription
extraction_failed422Browser failed to load the page
extraction_timeout422Page load timed out
page_blocked422Page blocked the extraction
invalid_content422Page returned non-HTML content

Example:

{
  "error": {
    "code": "extraction_failed",
    "message": "Failed to load page",
    "details": {
      "reason": "SSL certificate error",
      "url": "https://example.com"
    }
  }
}

Rate Limiting

CodeHTTP StatusDescription
rate_limited429Too many requests
usage_limit_exceeded429Monthly quota exceeded

Headers included:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1705312800
Retry-After: 60

Billing Errors

CodeHTTP StatusDescription
subscription_required402Feature requires paid plan
subscription_expired402Subscription has ended
payment_failed402Payment processing failed

Webhook Errors

CodeHTTP StatusDescription
webhook_delivery_failed—Webhook endpoint returned non-2xx
webhook_timeout—Endpoint didn’t respond in time
webhook_disabled—Webhook was disabled after failures

Internal Errors

CodeHTTP StatusDescription
internal_error500Unexpected server error
service_unavailable503Service temporarily unavailable

For 5xx errors, retry with exponential backoff. If the error persists, contact support.

Handling Errors

JavaScript

async function extractTokens(url) {
  const response = await fetch('https://api.stylegrab.dev/api/extractions', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ url })
  });
  
  if (!response.ok) {
    const error = await response.json();
    
    switch (error.error.code) {
      case 'rate_limited':
        const retryAfter = response.headers.get('Retry-After');
        await sleep(retryAfter * 1000);
        return extractTokens(url); // Retry
        
      case 'unauthorized':
        throw new Error('Invalid API key');
        
      case 'extraction_failed':
        console.error('Page could not be loaded:', error.error.details);
        return null;
        
      default:
        throw new Error(error.error.message);
    }
  }
  
  return response.json();
}

Python

import requests
import time

def extract_tokens(url):
    response = requests.post(
        'https://api.stylegrab.dev/api/extractions',
        headers={'Authorization': f'Bearer {API_KEY}'},
        json={'url': url}
    )
    
    if response.status_code == 429:
        retry_after = int(response.headers.get('Retry-After', 60))
        time.sleep(retry_after)
        return extract_tokens(url)
    
    if not response.ok:
        error = response.json()['error']
        raise Exception(f"{error['code']}: {error['message']}")
    
    return response.json()