LedeWire SDK API Reference
    Preparing search index...

    Class SpendCapReachedError

    Thrown when the buyer's daily spend cap has been reached. Returned as HTTP 402 by POST /v1/purchases, GET /v1/x402/contents/{id}, and acquisition authorization, whenever the API error body's error.type is 'daily_spend_cap_reached'.

    Funding the wallet does not clear this. Unlike a plain insufficient_funds 402 — where adding money to the wallet is enough to retry — a spend cap refusal is a daily policy limit on the buyer's account (every new buyer starts with a default cap). It clears only when the spend window rolls over at SpendCapReachedError.resetsAt, or when the buyer raises the cap via user.spendCap.update().

    try {
    await client.purchases.create({ content_id, price_cents })
    } catch (err) {
    if (err instanceof SpendCapReachedError) {
    // Do NOT prompt the buyer to fund their wallet — that won't help.
    console.error(
    `Spend cap reached: spent ${err.spentCents} of ${err.capCents} cents. ` +
    `Resets at ${err.resetsAt}.`,
    )
    }
    }

    Hierarchy (View Summary)

    Index
    • Parameters

      • message: string
      • capInfo: {
            bulkExempt: boolean;
            capCents: number;
            remainingCents: number;
            resetsAt: string;
            spentCents: number;
        }
      • Optionalcode: number

      Returns SpendCapReachedError

    bulkExempt: boolean

    Whether this buyer's bulk acquisitions are exempt from the cap. When true, spentCents and remainingCents describe ordinary spend only — an authorized bulk acquisition does not consume them.

    capCents: number

    The buyer's daily spend cap in cents.

    code: number | undefined

    Machine-readable error code from the API error body, if present.

    details: Readonly<Record<string, unknown>> | undefined

    Extra top-level fields from the API error response body, excluding error itself. For example, a selection_too_large refusal from POST /v1/acquisitions (422) carries maximum and submitted alongside error. undefined when the body carried no other top-level fields, which is the common case.

    remainingCents: number

    Cap minus spend so far, floored at zero — what the buyer may still spend in this window.

    resetsAt: string

    ISO 8601 timestamp (UTC) of the instant the current spend window rolls.

    retryAfter: number | undefined

    Seconds to wait before retrying, from the response's Retry-After header. undefined when the response carried no usable header. Present on rate-limit (429) and busy (503) refusals, so a caller can back off without guessing.

    spentCents: number

    Total spent so far in the current spend window.

    statusCode: number

    HTTP status code returned by the API (e.g. 400, 401, 404, 422).

    type: ErrorTypeValue | undefined

    Machine-readable reason from the API error body's error.type, if present. See ErrorType for the documented values and how to branch on them — the API may emit other values it hasn't documented yet, which still land here as a plain string rather than being dropped.

    brand: string

    Class-identity brand used for cross-bundle instanceof (see [Symbol.hasInstance]). Hardcoded per class — never derived from constructor.name or this.name, either of which a minifier can rewrite, silently breaking the brand match.

    • Makes err instanceof LedewireError (and every subclass below) true even when err was constructed by a different bundled copy of this module. Each published package (@ledewire/node, @ledewire/browser, @ledewire/x402-client) bundles its own copy of @ledewire/core via tsup, so the classes are distinct objects with unrelated prototypes — the plain prototype-chain check instanceof normally does would fail.

      Falls back to the brand list every instance carries under a Symbol.for('@ledewire/error-brands') key (collected from the brand static along the constructing class's prototype chain): true when the ordinary check passes, OR the instance's brand list includes this class's own brand.

      Parameters

      • instance: unknown

      Returns boolean