Skip to main content

PurseHeadlessCheckoutError

Description

Custom error class for handling errors specific to the Purse Headless Checkout SDK.

Example

let checkout: PurseHeadlessCheckout;

try {
checkout = await Purse.createHeadlessCheckout({
...
});
} catch(e) {
if (e instanceof PurseHeadlessCheckoutError) {
switch(e.code) {
case 'INVALID_INIT_PARAMS':
// Handle expired session
break;
// Handle other error codes as needed
default:
console.error('An unexpected error occurred:', e);
}
} else {
console.error('A non-headless checkout error occurred:', e);
}
}

Extends

  • Error

Constructors

Constructor

new PurseHeadlessCheckoutError(error, additionalPayload?): PurseHeadlessCheckoutError;

Parameters

ParameterType
error| { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: string; documentationLink: string; message: string; } | { code: "ELEMENT_NOT_FULFILLED"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#element_not_fulfilled"; message: "Payment element must be fulfilled for this action."; } | { code: "ELEMENT_RENDER_FAILED"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#element_render_failed"; message: "An error occurred while rendering the payment element"; } | { code: "INVALID_LOAN_SIMULATION"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#invalid_loan_simulation"; message: "The Load Simulation API response does not contain valid simulation data."; } | { code: "UI_VALIDATION_FAILED_ERROR"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#ui_validation_failed_error"; message: "Partner's form is not complete, sometimes the form internal state cannot be accessed and fulfilled is sent right on creation. Visual queues are displayed for the user."; } | { code: "USAGE_LIMIT_ERROR"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#usage_limit_error"; message: "Usage limit reached for partner and method."; } | { code: "SECONDARY_METHOD_REQUIRED_CVV"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#secondary_method_required_cvv"; message: "This method and pan combination requires a CVV."; } | { code: "SECONDARY_METHOD_WRONG_PAN_FORMAT"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#secondary_method_wrong_pan_format"; message: "The provided pan does not respect the expected format."; } | { code: "SECONDARY_METHOD_WRONG_CVV_FORMAT"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#secondary_method_wrong_cvv_format"; message: "The provided cvv does not respect the expected format."; } | { code: "SECONDARY_METHOD_TAKE_POLICY_VIOLATED"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#secondary_method_take_policy_violated"; message: "This method has a strict take policy and cannot be used with any amount."; } | { code: "METHOD_NOT_IMPLEMENTED"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#method_not_implemented"; message: "The invoked method is not implemented."; } | { code: "INVALID_TAKE_AMOUNT"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#invalid_take_amount"; message: "Cannot perform "take" with an invalid amount."; } | { code: "PAYMENT_NOT_FULFILLED_ON_SUBMIT"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#payment_not_fulfilled_on_submit"; message: "Payment not fulfilled while submitting payment."; } | { code: "PAYMENT_METHOD_NOT_FOUND"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#payment_method_not_found"; message: "Method not found."; } | { code: "UNKNOWN_ERROR"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#unknown_error"; message: "An error occurred."; } | { code: "ON_BEFORE_VALIDATE_HOOK_FAILED"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#on_before_validate_hook_failed"; message: "The hook onBeforeValidate failed."; } | { code: "NOT_SUPPORTED_BRAND"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#not_supported_brand"; message: "The brand is not supported."; } | { code: "BRAND_NOT_BELONGS_TO_DETECTED"; documentationLink: "https://docs.purse.tech/docs/integrate/purse-checkout/headless-checkout/error-handling/error-codes#brand_not_belongs_to_detected"; message: "The brand is not one of the detected ones"; }
additionalPayload?JsonSerializable | Error

Returns

PurseHeadlessCheckoutError

Overrides

Error.constructor

Properties

additionalPayload?

readonly optional additionalPayload: JsonSerializable | Error;

cause?

optional cause: unknown;

Inherited from

Error.cause

code

readonly code: 
| "EXPIRED_SESSION"
| "MISSING_SESSION"
| "MISSING_WALLET_SESSION"
| "SET_WALLET_SESSION_FAILED"
| "SESSION_MALFORMED"
| "METHOD_NOT_REGISTERABLE"
| "METHOD_DISABLED"
| "METHOD_IS_NOT_SIMULABLE"
| "TOKEN_NOT_REGISTERABLE"
| "TOKEN_NOT_REGISTERED"
| "TOKEN_NAME_EXISTS"
| "MISSING_TOKEN"
| "INVALID_TOKEN_NAME"
| "FAILED_TO_DELETE_ALL_TOKENS"
| "FAILED_TO_ADD_TOKEN"
| "PAYMENT_TOKEN_NOT_FOUND_IN_SESSION"
| "INVALID_INIT_PARAMS"
| "FAILED_TO_INIT_SECONDARY_TOKEN"
| "VALIDATE_FAILED"
| "POST_VALIDATE_FAILED"
| "ELEMENT_NOT_FULFILLED"
| "ELEMENT_RENDER_FAILED"
| "INVALID_LOAN_SIMULATION"
| "UI_VALIDATION_FAILED_ERROR"
| "USAGE_LIMIT_ERROR"
| "SECONDARY_METHOD_REQUIRED_CVV"
| "SECONDARY_METHOD_WRONG_PAN_FORMAT"
| "SECONDARY_METHOD_WRONG_CVV_FORMAT"
| "SECONDARY_METHOD_TAKE_POLICY_VIOLATED"
| "METHOD_NOT_IMPLEMENTED"
| "INVALID_TAKE_AMOUNT"
| "PAYMENT_NOT_FULFILLED_ON_SUBMIT"
| "PAYMENT_METHOD_NOT_FOUND"
| "UNKNOWN_ERROR"
| "ON_BEFORE_VALIDATE_HOOK_FAILED"
| "NOT_SUPPORTED_BRAND"
| "BRAND_NOT_BELONGS_TO_DETECTED";

readonly documentationLink: string;

message

message: string;

Inherited from

Error.message

name

name: string;

Inherited from

Error.name

stack?

optional stack: string;

Inherited from

Error.stack

stackTraceLimit

static 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.

Inherited from

Error.stackTraceLimit

Methods

captureStackTrace()

static captureStackTrace(targetObject, constructorOpt?): void;

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

ParameterType
targetObjectobject
constructorOpt?Function

Returns

void

Inherited from

Error.captureStackTrace

prepareStackTrace()

static prepareStackTrace(err, stackTraces): any;

Parameters

ParameterType
errError
stackTracesCallSite[]

Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

Error.prepareStackTrace