Triple.Error exception (triple v1.0.0)

Copy Markdown View Source

A structured error returned (or raised, via the ! functions) for every failure mode this library can produce: local validation failures, Triple API error responses, and transport-level failures.

Fields

  • :type — one of :validation, :unauthenticated, :forbidden, :not_found, :rate_limited, :server_error, :unexpected_status, or :network_error.
  • :message — a human-readable summary, suitable for logging.
  • :status — the HTTP status code, or nil for errors caught before any request was sent (e.g. local validation) or for network failures.
  • :errors — for :validation errors, a map of field => [messages] (mirrors the shape of Triple's own 400 responses).
  • :retry_after — for :rate_limited errors, the number of seconds Triple asked you to wait, parsed from the retry-after header, if present. Note: Triple.Client already retries 429s automatically (see Triple.Config), so you'll typically only observe a :rate_limited error after retries are exhausted.
  • :raw_body — the raw decoded response body, for cases this module's summarization doesn't cover.

Because this is a proper Exception, every error can be raised directly (raise error) and every context module exposes a ! variant that does this for you (e.g. Triple.Enrich.transaction!/2).

Summary

Types

error_type()

@type error_type() ::
  :validation
  | :unauthenticated
  | :forbidden
  | :not_found
  | :rate_limited
  | :server_error
  | :unexpected_status
  | :network_error

t()

@type t() :: %Triple.Error{
  __exception__: true,
  errors: %{optional(String.t()) => [String.t()]} | nil,
  message: String.t(),
  raw_body: term(),
  retry_after: non_neg_integer() | nil,
  status: pos_integer() | nil,
  type: error_type()
}