Rapyd.Error exception (rapyd v1.0.0)

Copy Markdown View Source

Structured error returned by every failed SDK operation.

Fields

  • :type — atom classifying the failure; pattern-match on this.
  • :message — human-readable summary.
  • :error_code — Rapyd API error code string (e.g. "ERROR_PAYMENT_NOT_FOUND").
  • :status_code — HTTP status code integer, or nil for network-level errors.
  • :operation_id — Rapyd operation_id from the response envelope, when present.
  • :retryable?true when the call can be safely retried.

Error Types

TypeMeaning
:api_errorGeneric Rapyd API error
:payment_not_foundPayment ID does not exist
:payment_failedPayment processing failure
:payment_canceledPayment was canceled
:insufficient_fundsInsufficient funds in wallet or card
:card_declinedCard was declined by the network
:expired_cardCard has expired
:invalid_cardCard number or CVV is invalid
:do_not_honorGeneric do-not-honor from card network
:fraudTransaction flagged as fraudulent
:rate_limitToo many requests; back off and retry
:unauthorizedInvalid access/secret key pair
:forbiddenOperation not permitted for this account
:not_foundResource does not exist
:validationRequest body failed client-side validation
:webhook_signatureWebhook HMAC signature mismatch
:networkTCP/TLS transport failure
:timeoutRequest timed out
:unknownUnclassified server error

Summary

Functions

Build an error from a decoded Rapyd API error envelope.

Build a transport-level (network or timeout) error.

Returns true when this error type is safe to retry.

Build a client-side validation error.

Build a webhook signature error.

Types

error_type()

@type error_type() ::
  :api_error
  | :payment_not_found
  | :payment_failed
  | :payment_canceled
  | :insufficient_funds
  | :card_declined
  | :expired_card
  | :invalid_card
  | :do_not_honor
  | :fraud
  | :rate_limit
  | :unauthorized
  | :forbidden
  | :not_found
  | :validation
  | :webhook_signature
  | :network
  | :timeout
  | :unknown

t()

@type t() :: %Rapyd.Error{
  __exception__: true,
  error_code: String.t() | nil,
  message: String.t(),
  operation_id: String.t() | nil,
  retryable?: boolean(),
  status_code: non_neg_integer() | nil,
  type: error_type()
}

Functions

from_api_response(body, http_status)

@spec from_api_response(map(), non_neg_integer()) :: t()

Build an error from a decoded Rapyd API error envelope.

The envelope looks like:

%{"status" => %{"status" => "ERROR", "error_code" => "...", "message" => "...",
                 "operation_id" => "..."}, ...}

from_exception(exc)

@spec from_exception(Exception.t()) :: t()

Build a transport-level (network or timeout) error.

retryable?(error)

@spec retryable?(t()) :: boolean()

Returns true when this error type is safe to retry.

validation(message)

@spec validation(String.t()) :: t()

Build a client-side validation error.

webhook_signature(message)

@spec webhook_signature(String.t()) :: t()

Build a webhook signature error.