API Reference@flopay/shared
Errors
FloPayError class and error factory functions exported by @flopay/shared.
FloPayErrorType
type FloPayErrorType =
| 'validation_error'
| 'api_error'
| 'authentication_error'
| 'rate_limit_error'
| 'network_error';Discriminated union of all error types returned by the FloPay SDK.
FloPayError
Custom error class for all FloPay SDK errors. Extends the native Error and adds structured fields.
Constructor
new FloPayError(
message: string,
type: FloPayErrorType,
options?: { code?: string; declineCode?: string; param?: string }
)| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Human-readable error message. |
type | FloPayErrorType | Yes | Error category. |
options.code | string | No | Machine-readable error code. |
options.declineCode | string | No | Card decline code (e.g. "insufficient_funds"). |
options.param | string | No | The parameter that caused the error. |
Properties
| Property | Type | Description |
|---|---|---|
message | string | Human-readable error message (inherited from Error). |
name | string | Always "FloPayError". |
type | FloPayErrorType | Error category. |
code | string | undefined | Machine-readable error code. |
declineCode | string | undefined | Card decline code. |
param | string | undefined | The parameter that caused the error. |
Example
import { FloPayError } from '@flopay/shared';
try {
// ...
} catch (err) {
if (err instanceof FloPayError) {
console.log(err.type); // 'validation_error'
console.log(err.param); // 'publishableKey'
}
}Factory Functions
Convenience functions that create FloPayError instances with the correct type.
validationError
function validationError(message: string, param?: string): FloPayErrorCreates a validation error (e.g. missing required field).
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Error message. |
param | string | No | The invalid parameter name. |
import { validationError } from '@flopay/shared';
throw validationError('Email is required', 'email');apiError
function apiError(message: string, code?: string): FloPayErrorCreates an API error (e.g. upstream provider returned an error).
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Error message. |
code | string | No | Machine-readable error code. |
authenticationError
function authenticationError(message: string): FloPayErrorCreates an authentication error (e.g. invalid publishable key).
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Error message. |
rateLimitError
function rateLimitError(message: string): FloPayErrorCreates a rate limit error.
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Error message. |
networkError
function networkError(message: string): FloPayErrorCreates a network error (e.g. fetch failed).
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | Error message. |