Skip to content

Error Handling

Common Error Responses

401 Unauthorized

json
{
  "message": "Unauthenticated."
}

Cause: Invalid or missing API token Solution: Verify your Authorization header format and token validity

402 Payment Required

json
{
  "message": "Subscription required."
}

Cause: No active subscription on your account Solution: Subscribe to a plan at the billing portal

422 Validation Error

json
{
  "message": "The html field is required.",
  "errors": {
    "html": ["The html field is required."]
  }
}

Cause: Missing or invalid html field in request Solution: Ensure your request includes the html parameter with valid HTML content

Error Handling Examples

JavaScript

javascript
try {
  const response = await fetch('https://app.offloadpdf.com/api/v1/pdf', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ html: '<h1>Test</h1>' })
  });

  if (!response.ok) {
    const error = await response.json();
    console.error('API Error:', error.message);
    return;
  }

  const data = await response.json();
  // Process successful response
} catch (error) {
  console.error('Request failed:', error);
}

PHP

php
<?php
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

$client = new Client([
    'base_uri' => 'https://app.offloadpdf.com',
    'headers' => [
        'Authorization' => 'Bearer YOUR_API_TOKEN',
        'Content-Type' => 'application/json',
    ]
]);

try {
    $response = $client->post('/api/v1/pdf', [
        'json' => ['html' => '<h1>Test</h1>']
    ]);
    $data = json_decode($response->getBody(), true);
    // Process successful response
} catch (ClientException $e) {
    $statusCode = $e->getResponse()->getStatusCode();
    $error = json_decode($e->getResponse()->getBody(), true);

    if ($statusCode === 401) {
        echo "Authentication failed: Check your API token";
    } elseif ($statusCode === 402) {
        echo "Subscription required";
    } elseif ($statusCode === 422) {
        echo "Validation error: " . $error['message'];
    }
}