Noizu.Discord.Error exception (Noizu.Discord v0.1.0)

Copy Markdown View Source

Structured error returned by every failing call as {:error, %Noizu.Discord.Error{}}.

Returned, never raised in the normal flow (it is a defexception so pagination streams can raise it mid-enumeration).

:tag:reasonWhen
:apiDiscord JSON error code (integer, e.g. 10003)non-2xx with the {code, message, errors} envelope
:rate_limited:rate_limited429 still returned after the bounded retry gave up
:http:http_errornon-2xx without a Discord envelope
:transportthe transport exceptionconnection refused, timeout, …
:config:missing_tokenno bot token configured
:validationan atom (e.g. :embed_too_long)client-side validation (embeds, webhook URL, …)
  • :status — HTTP status when a response arrived.
  • :body — decoded JSON (or raw body); for :api errors this holds the nested "errors" object describing field-level failures.
  • :summary — Discord's message string when present.

Summary

Functions

Missing configuration (e.g. no bot token).

Builds an error from an HTTP status and decoded response body.

Wraps a transport-level failure.

Client-side validation failure.

Types

t()

@type t() :: %Noizu.Discord.Error{
  __exception__: term(),
  body: term(),
  message: String.t(),
  reason: term(),
  status: pos_integer() | nil,
  summary: String.t() | nil,
  tag: :api | :rate_limited | :http | :transport | :config | :validation | nil
}

Functions

config(reason, message)

@spec config(atom(), String.t()) :: t()

Missing configuration (e.g. no bot token).

from_response(status, body)

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

Builds an error from an HTTP status and decoded response body.

transport(reason)

@spec transport(term()) :: t()

Wraps a transport-level failure.

validation(reason, message)

@spec validation(atom(), String.t()) :: t()

Client-side validation failure.