Developer reference

    Share link error contract

    Every public share-link endpoint (/share/document/<token>, /shared/<token>, /shared/citation/…) returns a stable JSON envelope on failure and emits a matching browser event so embedders can react without polling.

    JSON error envelope

    All non-2xx responses use the schema below. Use code to branch — the message is for humans only.

    {
      "error": {
        "code": "share_link_expired",        // stable machine token (snake_case)
        "message": "This share link expired on 2026-05-08.",
        "httpStatus": 410,                    // mirrors the HTTP status
        "retryable": false,                   // safe to auto-retry?
        "retryAfterSeconds": null,            // present on 429 / 503 when known
        "requestId": "req_01HX…",             // attach to support tickets
        "expiresAt": "2026-05-08T12:00:00Z",  // optional context fields
        "docsUrl": "https://aiboss.info/docs/share-link-errors"
      }
    }

    code

    Stable snake_case identifier. Never localised. Safe for switch statements and analytics.

    httpStatus

    Mirror of the HTTP status line so client code can reason about a single source of truth.

    retryable

    Boolean hint. true ⇒ transient, retry with backoff. false ⇒ permanent, escalate to UI.

    Error code catalogue

    The matrix below is authoritative. New codes will be appended; existing rows will not change semantics.

    codehttpStatusretryableMeaning
    share_link_invalid404falseToken does not match any known share. Almost always permanent — verify the URL or request a new link.
    share_link_revoked410falseThe share owner explicitly revoked access. The link will never become valid again.
    share_link_expired410falseThe expires_at timestamp has passed. Ask the owner to issue a fresh link.
    share_link_locked423falseOwner requires a passphrase or step-up auth. Render the unlock UI before retrying.
    share_link_quota_exceeded429trueView / download quota for this token is temporarily exhausted. Honour the Retry-After header.
    share_link_rate_limited429trueToo many requests from this client. Back off using exponential delay (2^n × 1s, max 60s).
    share_link_document_unavailable409trueThe underlying document is still ingesting or temporarily unreadable. Retry in a few seconds.
    share_link_storage_unavailable503trueStorage backend is degraded. Safe to retry; surface the system status link to the user.
    share_link_internal_error500trueUnhandled server error. Retry once; if it persists, log the request_id and contact support.
    share_link_bad_request400falseMalformed query (missing token, invalid format). Fix the request before retrying.

    Browser event: aiboss:share-link-error

    When the in-page share viewer encounters an error it dispatches a CustomEvent on window so host pages and embeds can react without monkey-patching fetch. The event bubbles, is composed (crosses shadow-DOM boundaries) and is non-cancelable.

    Event signature

    Type: CustomEvent<ShareLinkErrorDetail>

    interface ShareLinkErrorDetail {
      code: string;                 // e.g. "share_link_expired"
      httpStatus: number;           // 4xx / 5xx
      retryable: boolean;           // matches JSON envelope
      retryAfterSeconds: number | null;
      message: string;              // human-readable, already localised
      requestId: string | null;
      token: string;                // the share token (never the underlying doc id)
      surface: "document" | "analysis" | "citation";
      occurredAt: string;           // ISO 8601 UTC
    }
    
    window.addEventListener("aiboss:share-link-error", (event) => {
      const detail = (event as CustomEvent<ShareLinkErrorDetail>).detail;
      if (detail.retryable) scheduleRetry(detail.retryAfterSeconds ?? 5);
      else showFatal(detail.code, detail.message);
    });

    The event fires once per failed attempt, including auto-retry attempts. Deduplicate on requestId if you forward to analytics.

    DOM data attributes

    The share viewer mirrors the latest error onto its root element so you can target it from CSS, query selectors, or a MutationObserver without subscribing to the event bus.

    AttributeDescription
    data-share-state"loading" | "ready" | "error" — high-level lifecycle.
    data-share-error-codeMirror of detail.code. Absent when state ≠ error.
    data-share-error-statusNumeric HTTP status, e.g. "410".
    data-share-error-retryable"true" or "false". Use it to gate retry buttons via CSS:[data-share-error-retryable="false"] .retry-btn { display:none }.
    data-share-error-retry-afterSeconds until next safe retry. Empty when unknown.
    data-share-request-idServer-side request id for support escalation.

    Example markup

    <div
      id="aiboss-share-root"
      data-share-state="error"
      data-share-error-code="share_link_rate_limited"
      data-share-error-status="429"
      data-share-error-retryable="true"
      data-share-error-retry-after="30"
      data-share-request-id="req_01HX…"
    >
      …
    </div>

    Retry guidance

    • Only retry when retryable === true. Permanent codes should surface a clear UI affordance instead.
    • Honour retryAfterSeconds (or the Retry-After header) before scheduling the next attempt.
    • Use exponential backoff with full jitter — base 1s, cap 60s, max 5 attempts per page session.
    • Log requestId alongside any user-facing error so support can correlate quickly.