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. The Humaans API's structured error envelope (code,name,message,issues) is also extracted onto top-level fields when present.:network_error- A transport-level error occurred before a response was received (e.g. connection refused, DNS failure). Thereasonfield contains the underlying error.
Structured API error fields
When the API returns a structured error body, the following fields are populated:
code- Short error code, e.g."ValidationError","NotFound".name- Human-readable error name.api_message- The API's error message string. (Named to avoid shadowing theException.message/1callback, which returns a formatted display string.)issues- List of field-level validation errors (each typically a map withpathandmessagekeys).nilif not present.
The raw body is always retained for forward-compatibility with undocumented
fields.
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: 422, issues: issues}}
when is_list(issues) ->
{:invalid, issues}
{:error, %Humaans.Error{type: :api_error, status: 401}} ->
:unauthorized
{:error, %Humaans.Error{type: :network_error, reason: reason}} ->
{:network_failure, reason}
end
Summary
Functions
Builds an :api_error from an HTTP status and response body, extracting
the API's structured error fields when present.
Types
@type error_type() :: :api_error | :network_error
@type t() :: %Humaans.Error{ __exception__: true, api_message: String.t() | nil, body: any(), code: String.t() | nil, issues: [issue()] | nil, name: String.t() | nil, reason: any(), status: non_neg_integer() | nil, type: error_type() }
Functions
@spec from_api_response(non_neg_integer(), any()) :: t()
Builds an :api_error from an HTTP status and response body, extracting
the API's structured error fields when present.