Picnic.Error exception (Picnic v0.1.0)

Copy Markdown View Source

The error struct returned by every function in this library.

Errors are grouped into categories so callers can pattern-match on classes of failure instead of inspecting individual reasons or status codes:

  • :network — transport-level failure (timeout, DNS, refused connection)
  • :auth — authentication problem, e.g. reason: :unauthorized or reason: :two_factor_required
  • :rate_limit — HTTP 429; back off before retrying
  • :http — any other non-success HTTP status
  • :decode — the response body could not be parsed at all
  • :schema — the body parsed, but its overall shape was not what the requested struct expects

The :raw field carries the response body (or exception) that produced the error. Because the Picnic API is unofficial and drifts, :raw is the place to look when debugging an unexpected failure.

Picnic.Error is an exception, so the bang variants (Picnic.search!/3, …) raise it directly.

Summary

Types

category()

@type category() :: :network | :auth | :rate_limit | :http | :decode | :schema

t()

@type t() :: %Picnic.Error{
  __exception__: true,
  category: category(),
  message: String.t() | nil,
  raw: term(),
  reason: atom() | term(),
  status: nil | non_neg_integer()
}