Unit.Error exception (Unit v1.0.0)

Copy Markdown View Source

Structured error types returned by the Unit API client.

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

Error types

  • :api_error — The Unit API returned a 4xx/5xx error.
  • :network_error — HTTP transport failure (timeout, connection refused, etc.)
  • :decode_error — Response body could not be parsed as JSON:API.
  • :auth_error — 401 Unauthorized.
  • :rate_limit — 429 Too Many Requests.
  • :not_found — 404 Not Found.
  • :conflict — 409 Conflict.
  • :validation_error — 422 Unprocessable Entity.

Summary

Functions

Build a response-decode error.

Build an error from an HTTP response status code and body.

Build a network transport error.

Types

api_error_detail()

@type api_error_detail() :: %{
  title: String.t() | nil,
  detail: String.t() | nil,
  code: String.t() | nil,
  status: String.t() | nil,
  source: map() | nil,
  meta: map() | nil
}

classification()

@type classification() ::
  :api_error
  | :auth_error
  | :conflict
  | :not_found
  | :rate_limit
  | :validation_error

error_type()

@type error_type() ::
  :api_error
  | :network_error
  | :decode_error
  | :auth_error
  | :rate_limit
  | :not_found
  | :conflict
  | :validation_error

t()

@type t() :: %Unit.Error{
  __exception__: true,
  errors: [api_error_detail()],
  message: String.t() | nil,
  raw: term(),
  status: non_neg_integer() | nil,
  type: error_type()
}

Functions

decode(reason)

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

Build a response-decode error.

from_response(status, body)

@spec from_response(integer(), term()) :: t()

Build an error from an HTTP response status code and body.

network(reason)

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

Build a network transport error.