Guides
Error Handling
Handle payment errors with FloPayError types and factory functions.
Error Handling
All errors in the FloPay SDK use the FloPayError class from @flopay/shared. It extends Error with structured fields that mirror Stripe-style error responses.
FloPayError
Error Types
| Type | Description |
|---|---|
validation_error | A required field is missing or invalid (e.g., no publishable key) |
api_error | The upstream provider or billing API returned an error |
authentication_error | Invalid API key or credentials |
rate_limit_error | Too many requests |
network_error | Network connectivity failure (fetch failed) |
Additional Fields
code-- Provider-specific error code (e.g.,card_declined)declineCode-- Card decline reason (e.g.,insufficient_funds,lost_card)param-- The parameter that caused the error (e.g.,publishableKey,sessionId)
Factory Functions
@flopay/shared exports factory functions for creating errors:
Handling Errors in Components
Both CheckoutForm and SplitCardForm accept an onError callback:
Catching Errors from loadFloPay
loadFloPay throws a FloPayError if the publishable key is missing:
FloPayError restores the prototype chain with Object.setPrototypeOf, so instanceof checks work correctly even in environments that transpile class inheritance.