@bates-solutions/payments-core API Reference - v0.2.0
    Preparing search index...

    Class PaymentsError<Code>

    Base class for the errors each provider package throws (SquareError, StripeError, CloverError). It carries a provider-specific code, plus the HTTP status and raw details when the error came from an API response.

    Catch it to handle any provider's error in one place. instanceof PaymentsError matches an error from any copy of this package, so it still works when providers built on different core versions install separate copies. Checks against a subclass (instanceof SquareError) are ordinary prototype checks.

    try {
    await client.payments.create(input);
    } catch (error) {
    if (error instanceof PaymentsError) {
    console.error(error.name, error.code, error.statusCode);
    }
    throw error;
    }

    Type Parameters

    • Code extends string = string

      The provider's union of error codes.

    Hierarchy

    • Error
      • PaymentsError
    Index
    • Type Parameters

      • Code extends string = string

        The provider's union of error codes.

      Parameters

      • message: string
      • code: Code
      • OptionalstatusCode: number
      • Optionaldetails: unknown

      Returns PaymentsError<Code>

    code: Code

    Normalized error code. Each provider defines its own union.

    details?: unknown

    The raw error body or other context, if any.

    statusCode?: number

    HTTP status of the response that caused the error, if any.

    • Makes value instanceof PaymentsError true for an error from any copy of this package, not only this one. It looks for a brand that every copy puts on PaymentsError.prototype, so the prototype itself is not counted as an instance. On a subclass, such as SquareError, it is the usual prototype-chain check.

      It returns a plain boolean rather than a type predicate, so TypeScript keeps narrowing instanceof SquareError to SquareError.

      Parameters

      • value: unknown

      Returns boolean