Humaans.Error exception (Humaans v0.5.1)

Copy Markdown View Source

Represents an error returned by the Humaans API or HTTP layer.

Error types

  • :api_error - The API returned a non-2xx HTTP status code. The status field contains the HTTP status code and body contains the parsed response body.
  • :network_error - A transport-level error occurred before a response was received (e.g. connection refused, DNS failure). The reason field 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

error_type()

@type error_type() :: :api_error | :network_error

t()

@type t() :: %Humaans.Error{
  __exception__: true,
  body: map() | nil,
  reason: any(),
  status: non_neg_integer() | nil,
  type: error_type()
}