How to PDF API Error Handling

Robust error handling is the difference between a production PDF service that recovers gracefully and one that drops documents silently. SublimePDF's API uses standard HTTP status codes and structured JSON error responses so your application can diagnose failures, retry safely, and present meaningful messages to end users.

Follow the step-by-step instructions below, then use the free tool directly — no registration or download required.

Open Tool →

How to PDF API Error Handling — Step by Step

1

Understand the HTTP status code categories

2xx means success: the PDF was generated. 4xx means client error: your request has a problem (bad parameters, invalid template, authentication failure). 5xx means server error: something went wrong on SublimePDF's side and the request should be retried.

2

Parse the error response body

All error responses return JSON with three fields: 'error' (machine-readable code like 'invalid_template'), 'message' (human-readable explanation), and optionally 'details' (an array of specific validation issues). Always log the full response body.

3

Handle common 4xx errors

400 Bad Request: malformed JSON or missing required fields. 401 Unauthorized: invalid or missing API key. 403 Forbidden: key lacks required scope. 404 Not Found: invalid template ID or endpoint. 422 Unprocessable Entity: the template rendered but produced invalid output (e.g., LaTeX compilation error).

4

Implement retry logic for 5xx and 429

429 Too Many Requests: you've exceeded rate limits — read the Retry-After header and wait. 500/502/503: transient server issues — retry with exponential backoff (1s, 2s, 4s, 8s) up to 3–5 attempts. Never retry 4xx errors without changing the request.

5

Add monitoring and alerting

Track error rates by status code in your application metrics (Datadog, New Relic, CloudWatch). Alert when 4xx errors spike (indicates a deployment broke your request format) or when 5xx errors persist (indicates an API outage).

Pro Tips

  • 💡 Always check the Content-Type header before parsing the response — successful requests return application/pdf, while errors return application/json. Attempting to parse a PDF binary as JSON will crash your code.
  • 💡 Include the X-Request-Id from the error response in your logs and support tickets — SublimePDF's team can look up exactly what happened for that request.
  • 💡 Wrap your PDF generation calls in a try-catch that distinguishes between network errors (no response received) and API errors (response received with error status) — they require different handling strategies.
  • 💡 For 422 errors on template rendering, the 'details' field often contains the exact line number and error in the template. Pipe this to your logging system for fast debugging.

Privacy & Security

All processing happens directly in your browser. Your files are never uploaded to any server — they remain on your device throughout the entire process. SublimePDF uses WebAssembly technology for fast, secure, client-side processing.

Works Everywhere

This tool works on any modern browser — Chrome, Firefox, Safari, or Edge — on desktop, tablet, or mobile. No software to install. PDF is an open ISO standard supported by all major platforms.

How to PDF API Error Handling — FAQ

What does a 429 Too Many Requests error mean?
You've exceeded your plan's rate limit. The response includes a Retry-After header indicating how many seconds to wait before retrying. Queue excess requests and process them after the cooldown.
Should I retry on 400 Bad Request?
No. A 400 error means your request is malformed — retrying the same request will produce the same error. Fix the request payload (correct JSON syntax, add required fields) before resending.
How can I tell if an error is transient or permanent?
5xx errors and 429 are transient — retry them. 4xx errors (except 429) are permanent and require you to fix the request. Check the 'error' code in the response: 'rate_limited' and 'service_unavailable' are transient; 'invalid_template' and 'missing_field' are permanent.
Does the API return errors in the PDF itself?
No. If rendering fails, you receive an HTTP error response with JSON — never a partial or error PDF. A successful response always contains a valid, complete PDF document.

Ready to get started?

Use SublimePDF's free tools right now.

Open Tool