PlaidEx.Error (plaid_ex v1.0.0)

Copy Markdown View Source

Typed Plaid error struct with retry classification, suggested actions, and structured metadata for logging and observability.

Every error that can come from Plaid is classified into:

  • An error_type matching Plaid's taxonomy
  • A suggested_action for your application code
  • A retryable flag for the HTTP client's retry logic

Plaid error taxonomy

Plaid categorises errors into these types (from their API reference):

  • INVALID_REQUEST — malformed request parameters
  • INVALID_RESULT — Plaid returned an unexpected result
  • INVALID_INPUT — semantically invalid input (e.g., wrong access token)
  • INSTITUTION_ERROR — institution outage, timeout, or maintenance
  • RATE_LIMIT_EXCEEDED — API rate limit hit
  • API_ERROR — Plaid internal error
  • ITEM_ERROR — item-level errors (login required, no accounts, etc.)
  • ASSET_REPORT_ERROR — asset report specific errors
  • RECAPTCHA_ERROR — CAPTCHA challenge required
  • OAUTH_ERROR — OAuth flow errors
  • PAYMENT_ERROR — payment initiation errors
  • BANK_TRANSFER_ERROR — bank transfer errors
  • INCOME_VERIFICATION_ERROR — income verification errors
  • MICRODEPOSITS_ERROR — micro-deposit verification errors

Handling errors

case PlaidEx.API.Transactions.sync(config, access_token: token) do
  {:ok, page} ->
    process(page)

  {:error, %PlaidEx.Error{code: "ITEM_LOGIN_REQUIRED"}} ->
    # Send user back through Link to reconnect
    redirect_to_link_update_mode(item_id)

  {:error, %PlaidEx.Error{retryable: true} = error} ->
    # Safe to retry after delay
    schedule_retry(error)

  {:error, %PlaidEx.Error{} = error} ->
    # Non-retryable — needs human attention
    alert_on_call(error)
end

Summary

Functions

Constructs an Error from an Elixir/network exception.

Constructs an Error from a Plaid HTTP response.

Returns true if this is an institution-side problem (not user or developer error).

Returns true if this error requires the user to re-authenticate via Link.

Returns true if this error should trigger an automatic retry.

Returns a loggable map with sensitive fields removed.

Types

error_type()

@type error_type() ::
  :invalid_request
  | :invalid_result
  | :invalid_input
  | :institution_error
  | :rate_limit_exceeded
  | :api_error
  | :item_error
  | :asset_report_error
  | :recaptcha_error
  | :oauth_error
  | :payment_error
  | :bank_transfer_error
  | :income_verification_error
  | :microdeposits_error
  | :unknown

suggested_action()

@type suggested_action() ::
  :retry
  | :retry_with_delay
  | :reauthenticate
  | :contact_support
  | :no_action
  | :update_item
  | :check_institution
  | :check_plaid_status

t()

@type t() :: %PlaidEx.Error{
  causes: [map()],
  code: String.t(),
  display_message: String.t() | nil,
  institution_id: String.t() | nil,
  message: String.t(),
  request_id: String.t() | nil,
  requires_reauthentication: boolean(),
  retryable: boolean(),
  status: integer(),
  suggested_action: suggested_action(),
  type: error_type()
}

Functions

from_exception(exception)

@spec from_exception(map()) :: t()

Constructs an Error from an Elixir/network exception.

from_plaid_response(status, body)

@spec from_plaid_response(integer(), map()) :: t()

Constructs an Error from a Plaid HTTP response.

institution_error?(arg1)

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

Returns true if this is an institution-side problem (not user or developer error).

requires_reauthentication?(error)

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

Returns true if this error requires the user to re-authenticate via Link.

retryable?(error)

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

Returns true if this error should trigger an automatic retry.

to_log_map(error)

@spec to_log_map(t()) :: map()

Returns a loggable map with sensitive fields removed.