ExLine.Error exception (ExLine v0.1.0)

Copy Markdown View Source

Normalized error returned by ExLine API calls.

kind classifies the failure so callers can decide whether to retry:

  • :transient — server-side or timeout statuses (408/500/502/503/504); safe to retry.
  • :quota_exceeded — HTTP 429, the monthly push quota / rate limit was hit.
  • :permanent — any other non-2xx status (4xx); retrying will not help.
  • :network — the request never got a response (connection error, timeout at the transport layer); safe to retry.

Ref: https://developers.line.biz/en/reference/messaging-api/#error-responses

Summary

Functions

Classifies a non-2xx HTTP status into an ExLine.Error.

Builds an error for a transport-level failure (no HTTP response received).

Whether the error is worth retrying (:transient or :network).

Types

kind()

@type kind() :: :transient | :quota_exceeded | :permanent | :network

t()

@type t() :: %ExLine.Error{
  __exception__: term(),
  body: term(),
  kind: kind(),
  reason: term(),
  status: pos_integer() | nil
}

Functions

from_status(status, body)

@spec from_status(pos_integer(), term()) :: t()

Classifies a non-2xx HTTP status into an ExLine.Error.

iex> ExLine.Error.from_status(429, %{}).kind
:quota_exceeded

iex> ExLine.Error.from_status(503, %{}).kind
:transient

iex> ExLine.Error.from_status(400, %{}).kind
:permanent

network(reason)

@spec network(term()) :: t()

Builds an error for a transport-level failure (no HTTP response received).

retryable?(error)

@spec retryable?(t()) :: boolean()

Whether the error is worth retrying (:transient or :network).

iex> ExLine.Error.retryable?(%ExLine.Error{kind: :transient})
true

iex> ExLine.Error.retryable?(%ExLine.Error{kind: :permanent})
false