ExNtfy.Error exception (ex_ntfy v0.1.0)

Copy Markdown View Source

The error type for all ExNtfy failures.

HTTP-level failures carry ntfy's JSON error fields (code, http, error, link); transport-level failures carry the underlying exception in reason, and a 2xx response whose body isn't a parsable message carries {:invalid_response, details} there. Implements Exception, so it can be raised or rendered with Exception.message/1.

Summary

Functions

Wraps a transport-level exception (e.g. Req.TransportError).

Builds an error from a non-2xx HTTP response.

Types

t()

@type t() :: %ExNtfy.Error{
  __exception__: term(),
  code: integer() | nil,
  error: String.t() | nil,
  http: integer() | nil,
  link: String.t() | nil,
  reason: Exception.t() | {:invalid_response, term()} | nil
}

Functions

from_exception(exception)

@spec from_exception(Exception.t()) :: t()

Wraps a transport-level exception (e.g. Req.TransportError).

from_response(status, body)

@spec from_response(non_neg_integer(), map() | binary() | nil) :: t()

Builds an error from a non-2xx HTTP response.

Accepts the body as an already-decoded map (Req decodes JSON responses), a raw JSON binary, a plain-text binary, or an empty/absent body. The http field prefers ntfy's own "http" value, falling back to the response status.