Coinfat

Checkout SDK

Error handling

The onError callback receives a CheckoutApiError with everything you need to branch on failures.

The error object

CheckoutApiError is exported from the package and carries these fields:

PropertyTypeDescription
statusnumberHTTP status. 0 for a network or transport failure.
messagestringThe server's message.
errorsRecord<string, string[]>Field-keyed validation messages, from a 422.
retryAfternumberSeconds to back off, from a 429.

Handling errors

onError
import {Coinfat, CheckoutApiError} from "@coinfat/checkout";
coinfat.checkout({
invoice: ulid,
display: "inline",
mount: "#pay",
onError: (error) => {
if (error instanceof CheckoutApiError && error.status === 429) {
// rate limited — the widget is already backing off
}
}
});

From the script-tag build, the same class hangs off the global as Coinfat.CheckoutApiError.