Returned for a controller response that failed but is not an authentication (401/403) or rate-limit (429) failure.
Two situations produce it:
- A non-2xx HTTP status —
:statusis that status and:codeisnil. - A v1 envelope error — the legacy
/api/s/...endpoints answer200 OKcarrying%{"meta" => %{"rc" => "error", "msg" => code}}.:statusis then the HTTP status (normally200) and:codeis the controller's error code, e.g."api.err.LoginRequired".
As with the other error structs the raw body is not retained; see
UnifiApi.Client.scrub_body_preview/1.
Example
case UnifiApi.Network.Networks.create(client, site_id, params) do
{:ok, network} ->
handle(network)
{:error, %UnifiApi.ApiError{status: 409}} ->
:conflict
{:error, %UnifiApi.ApiError{code: "api.err.LoginRequired"}} ->
:session_expired
end
Summary
Types
@type t() :: %UnifiApi.ApiError{ __exception__: true, body_preview: binary() | nil, code: String.t() | nil, status: non_neg_integer() | nil }