Errors
Every failure raised by the SDK is a PoliPage::Error subclass. Catch a specific subclass when you want narrow control (rescue PoliPage::RateLimitError), or rescue PoliPage::Error to handle every SDK failure at once. The code: reader is the machine-readable string; request_id: is what to quote on a support ticket.
The error hierarchy
Section titled “The error hierarchy”require "poli_page"
client = PoliPage::Client.new(api_key: ENV.fetch("POLI_PAGE_API_KEY"))
begin client.render.pdf(project: "billing", template: "invoice", data: {})rescue PoliPage::Error => e warn "#{e.class}: #{e.code} (request_id=#{e.request_id})"endHTTP status maps to a subclass via PoliPage::Internal::HTTP.classify:
400→ValidationError401→AuthenticationError403→PermissionDeniedError404→NotFoundError410→GoneError429→RateLimitError- other 4xx / 5xx →
APIError
The SDK-internal subclasses (InvalidOptionsError, ConnectionError, TimeoutError, DownloadError, InvalidResponseError, FileWriteError, InternalError) are raised before any HTTP call, in response to a network-layer failure, or by the SDK itself:
InvalidResponseError(invalid_response): a 2xx answer whose body is not JSON, from a method that expects JSON (render.document,render.pdf,render.pdf_stream,documents.get,documents.thumbnails). It usually comes from a proxy or a captive portal.statusis the real 2xx,request_idthe answer’sx-request-id. Never retried.FileWriteError(io_error):render_to_filecould not write the file. No status, the Ruby error as#cause, never retried; the target file is left untouched.
API codes
Section titled “API codes”Returned by the Poli Page API. Uppercase, snake-case. The SDK forwards the code verbatim into Error#code.
| Code | When | Recovery |
|---|---|---|
INVALID_API_KEY | The API key is malformed or revoked, or its environment or service account was deleted or disabled. | Create a new key in the dashboard for the environment you render in. |
API_KEY_EXPIRED | The key's expiry has passed (401). | Not retried: create a new key in the dashboard and update `POLI_PAGE_API_KEY`. |
PROJECT_OUT_OF_SCOPE | The key is restricted to other projects than the one rendered (403). Not the playground's `400 PROJECT_NOT_ALLOWED`. | Not retried: use a key that includes the project. |
MISSING_API_KEY | No API key was provided in the request. | Pass `api_key:` to the constructor. |
PROJECT_NOT_FOUND | No project with this slug in the organization. | Check the `project:` slug. |
PROJECT_NOT_IN_ENVIRONMENT | The project was never published in the key's environment, or was removed from it. | Publish the project to the key's environment, or use a key of the environment it is published in. |
TEMPLATE_NOT_FOUND | The template is absent from the environment's published copy of the project. | Check the `template:` slug, then publish the project again if the template is new. |
DOCUMENT_NOT_FOUND | No stored document matches the `document_id`. | Verify the id. |
DOCUMENT_GONE | The document was deleted, or is a `sandbox` document older than 30 days (410). | Render it again. |
VALIDATION_ERROR | The request body failed validation, e.g. thumbnail options out of bounds. | Read `message` for the field at fault. |
MISSING_DATA | The request body lacks a required `data` field. | Pass `data: {}` (or with values) on every render call. |
ENVIRONMENT_PROTECTED | `documents.delete` in a protected environment by a key without the owner or admin role. | Delete with a key that has the owner or admin role. |
ORGANIZATION_PAYMENT_GRACE | The organization has unpaid invoices and is read-only. | Update the payment method in the dashboard. |
RATE_LIMIT_EXCEEDED | Too many render requests for this key in a short window. | Automatically retried; spread the load if it persists. |
QUOTA_EXCEEDED | The monthly PDF quota is reached (`sandbox` renders do not count). | Not retried: it lasts until the monthly reset. Upgrade the plan for more renders. |
OVERAGE_CAP_EXCEEDED | The overage cap is reached (paid tiers). | Not retried: raise the cap in the dashboard. |
STORAGE_ACCESS_DENIED | Your bring-your-own bucket refuses access (502). | Not retried: restore the bucket role. |
TEMPLATE_UNSAFE | The template, a partial or an SVG asset holds an injection attempt (400); the message names it. | Not retried: remove the offending content and publish again. |
PUBLISH_IN_PROGRESS | The project is being published into this environment (503, with `Retry-After`). | Automatically retried after the `Retry-After` delay. |
INTERNAL_ERROR | The API returned 5xx. | Automatically retried; contact support if it persists. |
The full list of API codes lives in the reference.
Predicate helpers
Section titled “Predicate helpers”PoliPage::Error exposes #auth_error? (status 401 or 403), #rate_limit_error? (429), #validation_error? (400), #network_error? (code network_error or timeout), and #retryable? for callers who want a single rescue clause backed by introspection. They read status and code, not the class, so a DownloadError with a storage 403 is an auth_error?. #retryable? is true for a network error, a timeout, a 5xx or a 429, except QUOTA_EXCEEDED, OVERAGE_CAP_EXCEEDED, STORAGE_ACCESS_DENIED, DOWNLOAD_FAILED, invalid_response and io_error.
The SDK’s own messages are fixed texts: Network request failed, Request timed out after <ms>ms, Failed to download PDF: HTTP <status>, Failed to download PDF: network error or Failed to download PDF: timeout, Invalid response: HTTP <status> body is not JSON, Failed to write PDF: <reason>, apiKey is required, project is required, and HTTP <status> for an error answer whose body is not JSON. For a network error, a timeout or a failed download, #cause is the HTTP library’s exception; for invalid_response the JSON parser’s error; for io_error the file system’s error.
Framework integrations: to_payload
Section titled “Framework integrations: to_payload”Error#to_payload returns the HTTP body an integration answers with: exactly the keys code:, message:, status: and requestId:, the same JSON in every Poli Page SDK. status: is the API status, 503 for network_error, 504 for timeout, 502 for invalid_response (whose own status stays the real 2xx), and nil when unknown.
rescue PoliPage::Error => e e.to_payload # => { code: "TEMPLATE_NOT_FOUND", message: "...", status: 404, requestId: "req_..." }endExample
Section titled “Example”require "poli_page"
client = PoliPage::Client.new(api_key: ENV.fetch("POLI_PAGE_API_KEY"))
begin pdf = client.render.pdf( project: "billing", template: "invoice", data: { invoiceNumber: "INV-001" } )rescue PoliPage::RateLimitError => e # Custom strategy beyond the SDK's built-in retries. warn "rate limited (request_id=#{e.request_id}); backing off"rescue PoliPage::Error => e warn "render failed: #{e.code} (#{e.class})" raiseend