UnifiApi.AuthError exception (UnifiApi v0.4.0)

Copy Markdown View Source

Returned when the controller responds with HTTP 401 or 403.

The raw response :body is not stored — it can leak sensitive details via Inspect/Logger/Sentry. A scrubbed, truncated :body_preview (URL/host-like patterns redacted, ≤ 128 chars) is provided for diagnostics. See UnifiApi.Client.scrub_body_preview/1.

Example

case UnifiApi.Network.Sites.list(client) do
  {:ok, sites} ->
    handle(sites)

  {:error, %UnifiApi.AuthError{reason: :unauthorized}} ->
    # API key invalid or expired
    :reauth

  {:error, %UnifiApi.AuthError{reason: :forbidden}} ->
    # API key valid but lacks permission for this resource
    :no_access
end

Summary

Types

reason()

@type reason() :: :unauthorized | :forbidden

t()

@type t() :: %UnifiApi.AuthError{
  __exception__: true,
  body_preview: binary() | nil,
  reason: reason(),
  status: 401 | 403
}