FloPay
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 }
)
ParameterTypeRequiredDescription
messagestringYesHuman-readable error message.
typeFloPayErrorTypeYesError category.
options.codestringNoMachine-readable error code.
options.declineCodestringNoCard decline code (e.g. "insufficient_funds").
options.paramstringNoThe parameter that caused the error.

Properties

PropertyTypeDescription
messagestringHuman-readable error message (inherited from Error).
namestringAlways "FloPayError".
typeFloPayErrorTypeError category.
codestring | undefinedMachine-readable error code.
declineCodestring | undefinedCard decline code.
paramstring | undefinedThe 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): FloPayError

Creates a validation error (e.g. missing required field).

ParameterTypeRequiredDescription
messagestringYesError message.
paramstringNoThe invalid parameter name.
import { validationError } from '@flopay/shared';
 
throw validationError('Email is required', 'email');

apiError

function apiError(message: string, code?: string): FloPayError

Creates an API error (e.g. upstream provider returned an error).

ParameterTypeRequiredDescription
messagestringYesError message.
codestringNoMachine-readable error code.

authenticationError

function authenticationError(message: string): FloPayError

Creates an authentication error (e.g. invalid publishable key).

ParameterTypeRequiredDescription
messagestringYesError message.

rateLimitError

function rateLimitError(message: string): FloPayError

Creates a rate limit error.

ParameterTypeRequiredDescription
messagestringYesError message.

networkError

function networkError(message: string): FloPayError

Creates a network error (e.g. fetch failed).

ParameterTypeRequiredDescription
messagestringYesError message.

On this page