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.:statusis the HTTP status,:codeDiscord's JSON error code,:messageits explanation and:errorsthe per-field errors, if any.:rate_limited- the request would have to wait longer than allowed (seeLingo.with_max_wait/2) or kept getting 429s.:retry_afteris in ms.:server_error- Discord kept answering 5xx;:statusis the last one.:transport- the request never got an answer;:detailssays 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
@type reason() :: :api | :rate_limited | :server_error | :transport | :index_not_ready
@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 }