Exact.Error exception (exact_online v0.1.0)

Copy Markdown View Source

An Exact Online API or transport failure.

Every Exact function returns {:error, %Exact.Error{}} instead of raising, except for the bang variants. Match on :reason rather than on :status so transport failures are covered too.

reasonwhen
:validation400, the request or payload was rejected
:unauthorized401, the token is missing, expired or revoked
:forbidden403, the token lacks the scope or division access
:not_found404
:rate_limited429, check :rate_limit and :retry_after
:server_error5xx
:http_errorany other non-2xx status
:transportthe request never got a response

Summary

Functions

Builds an error from a transport level exception.

Builds an error from a non-2xx Req.Response.

Types

reason()

@type reason() ::
  :validation
  | :unauthorized
  | :forbidden
  | :not_found
  | :rate_limited
  | :server_error
  | :http_error
  | :transport

t()

@type t() :: %Exact.Error{
  __exception__: true,
  body: term(),
  code: String.t() | nil,
  message: String.t(),
  rate_limit: Exact.RateLimit.t() | nil,
  reason: reason(),
  retry_after: integer() | nil,
  status: pos_integer() | nil
}

Functions

from_exception(exception)

@spec from_exception(Exception.t()) :: t()

Builds an error from a transport level exception.

from_response(response)

@spec from_response(Req.Response.t()) :: t()

Builds an error from a non-2xx Req.Response.