glassnode-api - v0.29.3
    Preparing search index...

    Class GlassnodePaymentError

    An x402 paid call failed in the payment layer. Only raised by a fetch built with createX402Fetch (from glassnode-api/x402), and never retried by the client. Two cases, told apart by GlassnodePaymentError.paymentMayHaveSettled:

    • false — nothing was paid: the payment layer (@x402/fetch) failed before a paid request was sent, e.g. every payment requirement the server offered was above maxPaymentPerCall (or x402's own spend controls), the signer failed, or the server's 402 carried no usable payment requirements. The same request would fail the same way.
    • true — a request carrying a signed payment was sent, and the call then failed: either the paid request failed in transit (connection reset, or the timeout abort), or it was answered with a non-2xx HTTP status other than 402 (e.g. a gateway 502/504, a 429, a 400). The server (or the origin behind a proxy) may already have received the payment and settled it on-chain, so a retry would sign a new payment and could charge twice. Check the payer's on-chain transfers before retrying. For a transport failure the original error is on .cause and GlassnodePaymentError.timedOut says whether it was the per-request timeout; for an HTTP failure GlassnodePaymentError.status is set and .cause is the GlassnodeApiError (with status, statusText, detail) the response amounts to.

    The original error is on .cause. A transport failure or 429/5xx of the unpaid request (before any payment was signed) stays a retryable GlassnodeNetworkError / GlassnodeApiError; a 402 answer to the paid request (the server refused the payment, e.g. insufficient USDC) stays a GlassnodeApiError with status 402, which is never retried either.

    Hierarchy (View Summary)

    Index
    • Parameters

      • message: string
      • Optionaloptions: {
            cause?: unknown;
            paymentMayHaveSettled?: boolean;
            status?: number;
            timedOut?: boolean;
        }

      Returns GlassnodePaymentError

    cause?: unknown
    message: string
    name: string
    paymentMayHaveSettled: boolean

    True when a signed payment had already been sent to the server when the call failed, so the payment may have settled even though no usable response was received. Do not blindly retry.

    stack?: string
    status?: number

    HTTP status of the response to the paid request, when the call failed because that response was not 2xx (the matching GlassnodeApiError is on .cause). undefined when no such response was received (a payment-layer or transport failure).

    timedOut: boolean

    True when the failure was the per-request timeout (an AbortSignal.timeout() abort) firing on the paid request. Always false when paymentMayHaveSettled is false.

    stackTraceLimit: number

    The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

    The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

    If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

    • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

      const myObject = {};
      Error.captureStackTrace(myObject);
      myObject.stack; // Similar to `new Error().stack`

      The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

      The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

      The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

      function a() {
      b();
      }

      function b() {
      c();
      }

      function c() {
      // Create an error without stack trace to avoid calculating the stack trace twice.
      const { stackTraceLimit } = Error;
      Error.stackTraceLimit = 0;
      const error = new Error();
      Error.stackTraceLimit = stackTraceLimit;

      // Capture the stack trace above function b
      Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
      throw error;
      }

      a();

      Parameters

      • targetObject: object
      • OptionalconstructorOpt: Function

      Returns void