MoneyHub.Error exception (MoneyHub v1.0.0)

Copy Markdown View Source

A structured error returned by MoneyHub functions.

Every public function in this library that can fail returns {:error, %MoneyHub.Error{}} (or raises a MoneyHub.Error from the ! variants) rather than ad-hoc tuples, so callers can pattern match on reason regardless of where in the stack the failure occurred.

Reasons

  • :config_error - the MoneyHub.Config passed in was invalid.
  • :network_error - the HTTP transport failed (DNS, TLS, connect timeout, connection reset, etc). cause holds the underlying exception or Mint/Finch error term.
  • :api_error - the API responded with a non-2xx status. status and body are populated; code is the Moneyhub-specific error code from the response body when present (e.g. "INVALID_REQUEST").
  • :rate_limited - the API responded 429. retry_after (integer seconds) is populated when the Retry-After header was present.
  • :decode_error - the response body could not be parsed as JSON or did not match the expected shape.
  • :jwt_error - signing or verifying a JWT (client assertion, id_token, webhook payload) failed. cause holds the underlying reason.
  • :validation_error - a function argument failed local validation before any request was made (for example an invalid claims map).

Summary

Types

reason()

@type reason() ::
  :config_error
  | :network_error
  | :api_error
  | :rate_limited
  | :decode_error
  | :jwt_error
  | :validation_error

t()

@type t() :: %MoneyHub.Error{
  __exception__: true,
  body: term(),
  cause: term(),
  code: String.t() | nil,
  message: String.t(),
  reason: reason(),
  retry_after: non_neg_integer() | nil,
  status: pos_integer() | nil
}