Lithic.Error exception (Lithic v1.0.0)

Copy Markdown View Source

Structured error types for the Lithic client.

All public API functions return {:ok, result} or {:error, Lithic.Error.t()}.

Error Categories

  • :api_error — HTTP 4xx/5xx response from Lithic
  • :network_error — TCP/DNS/timeout failure
  • :config_error — Missing or invalid configuration
  • :decode_error — JSON decode or type-cast failure
  • :rate_limit — HTTP 429 Too Many Requests
  • :auth_error — HTTP 401 Unauthorized
  • :validation_error — HTTP 400 Bad Request / HTTP 422
  • :not_found — HTTP 404

Summary

Functions

Build a configuration error struct. Raise it with raise/1 at the call site.

Build a JSON decode error.

Build an error from an HTTP response.

Build a network/transport error.

Types

category()

@type category() ::
  :api_error
  | :network_error
  | :config_error
  | :decode_error
  | :rate_limit
  | :auth_error
  | :validation_error
  | :not_found

t()

@type t() :: %Lithic.Error{
  __exception__: true,
  body: map() | String.t() | nil,
  category: category(),
  message: String.t(),
  request_id: String.t() | nil,
  status: non_neg_integer() | nil
}

Functions

config(message)

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

Build a configuration error struct. Raise it with raise/1 at the call site.

decode(reason)

@spec decode(term()) :: t()

Build a JSON decode error.

from_response(status, body, request_id \\ nil)

@spec from_response(non_neg_integer(), map() | String.t(), String.t() | nil) :: t()

Build an error from an HTTP response.

network(reason)

@spec network(term()) :: t()

Build a network/transport error.