Pluggy.Error (PluggyAI v0.1.0)

Copy Markdown View Source

Represents an error returned by the Pluggy API or a transport-level failure.

Fields

  • :code - HTTP status code (integer) or :transport for connection errors
  • :message - Human-readable error message
  • :code_description - Optional machine-readable error code from the API
  • :data - Optional additional error data from the API

Summary

Functions

Builds an error from an API response body (already snake_cased by the pipeline).

Builds an error for transport-level failures (timeout, connection refused, etc.).

Types

t()

@type t() :: %Pluggy.Error{
  code: integer() | :transport,
  code_description: String.t() | nil,
  data: map() | nil,
  message: String.t()
}

Functions

from_response(response)

@spec from_response(map()) :: t()

Builds an error from an API response body (already snake_cased by the pipeline).

Examples

iex> Pluggy.Error.from_response(%{code: 401, message: "Unauthorized"})
%Pluggy.Error{code: 401, message: "Unauthorized"}

iex> Pluggy.Error.from_response(%{code: 400, message: "Bad Request", code_description: "VALIDATION_ERROR", data: %{field: "amount"}})
%Pluggy.Error{code: 400, message: "Bad Request", code_description: "VALIDATION_ERROR", data: %{field: "amount"}}

transport(reason)

@spec transport(atom() | String.t()) :: t()

Builds an error for transport-level failures (timeout, connection refused, etc.).

Examples

iex> Pluggy.Error.transport(:timeout)
%Pluggy.Error{code: :transport, message: "timeout"}