Lingo.Error exception (Lingo v0.4.2)

Copy Markdown View Source

A failed Discord API call.

Every REST function returns {:error, %Lingo.Error{}} on failure, and the ! helpers raise it. Match on :reason to tell failures apart:

  • :api - Discord rejected the request. :status is the HTTP status, :code Discord's JSON error code, :message its explanation and :errors the per-field errors, if any.
  • :rate_limited - the request would have to wait longer than allowed (see Lingo.with_max_wait/2) or kept getting 429s. :retry_after is in ms.
  • :server_error - Discord kept answering 5xx; :status is the last one.
  • :transport - the request never got an answer; :details says why.
  • :index_not_ready - message search gave up waiting for Discord to index the guild.
case Lingo.Api.Message.get(channel_id, message_id) do
  {:ok, message} -> message
  {:error, %Lingo.Error{status: 404}} -> nil
end

Summary

Types

reason()

@type reason() :: :api | :rate_limited | :server_error | :transport | :index_not_ready

t()

@type t() :: %Lingo.Error{
  __exception__: true,
  code: integer() | nil,
  details: term(),
  errors: map() | nil,
  message: String.t() | nil,
  reason: reason(),
  retry_after: non_neg_integer() | nil,
  status: pos_integer() | nil
}