For the complete documentation index, see llms.txt. This page is also available as Markdown.

Errors & Warnings

Error handling

When a call fails, its promise rejects with a ClientApiError carrying three properties:

  • error — machine-readable error code.

  • message — human-readable explanation.

  • status — the HTTP status of the failed request.

try {
  await SL.client.recommendations.subscribe({ email, uuids });
} catch (error) {
  if (error.name === "ClientApiError") {
    console.error(error.error, error.message);
  }
}

The errors you're most likely to run into:

  • bad_request (400) — a required argument is missing or invalid: a missing or malformed email, or a missing uuid or uuids.

  • not_found (404) — the uuid you passed doesn't match any of your recommendations or offers.

  • forbidden (403) — the Client API is not enabled for your publication, or the page's origin is not registered as an allowed origin. See Early Access to get it enabled or add a domain.

If the SparkLoop script itself fails to initialize, SL.client methods reject with a regular Error instead of a ClientApiError.

Never cache recommendations or offers

To stay safe:

  • Never cache or store recommendations or offers — not even for a few hours.

  • generate right before displaying, and subscribe/claim right after the reader acts.

  • When spotlighting an individual recommendation or offer, fetch it right before displaying it and check its recommendable field.