Represents an error returned by the Humaans API or HTTP layer.
Error types
:api_error- The API returned a non-2xx HTTP status code. Thestatusfield contains the HTTP status code andbodycontains the parsed response body.:network_error- A transport-level error occurred before a response was received (e.g. connection refused, DNS failure). Thereasonfield contains the underlying error.
Examples
case Humaans.People.retrieve(client, "missing-id") do
{:ok, person} ->
person
{:error, %Humaans.Error{type: :api_error, status: 404}} ->
:not_found
{:error, %Humaans.Error{type: :api_error, status: 401}} ->
:unauthorized
{:error, %Humaans.Error{type: :network_error, reason: reason}} ->
{:network_failure, reason}
end
Summary
Types
@type error_type() :: :api_error | :network_error
@type t() :: %Humaans.Error{ __exception__: true, body: map() | nil, reason: any(), status: non_neg_integer() | nil, type: error_type() }