Image.Plug.Error (image_plug v0.1.0)

Copy Markdown View Source

Tagged error type returned by every public function in Image.Plug.

An error carries a stable :tag (an atom suitable for pattern matching and for mapping to HTTP status codes), a human-readable :message, and optional :details for diagnostic context.

Errors are returned as {:error, %Image.Plug.Error{}}. They are not raised — try/rescue is reserved for true system boundaries per the project's code style.

Summary

Types

t()

A stable error tag. The set is open; callers should match the tags documented for the function they call and treat unknown tags as :internal.

Functions

Builds an error struct.

Maps an error tag to a default HTTP status code.

Types

t()

@type t() :: %Image.Plug.Error{details: map(), message: String.t(), tag: tag()}

tag()

@type tag() ::
  :unknown_option
  | :invalid_option
  | :malformed_url
  | :variant_not_found
  | :variant_already_exists
  | :source_not_found
  | :source_fetch_error
  | :source_too_large
  | :unsupported_source_format
  | :unsupported_output_format
  | :unsupported_option
  | :output_too_large
  | :request_timeout
  | :pipeline_failed
  | :signature_required
  | :invalid_signature
  | :signature_expired
  | :not_implemented
  | :internal

A stable error tag. The set is open; callers should match the tags documented for the function they call and treat unknown tags as :internal.

Functions

new(tag, message, options \\ [])

@spec new(tag(), String.t(), keyword()) :: t()

Builds an error struct.

Arguments

  • tag is an atom from tag/0 describing the error class.

  • message is a human-readable description of the failure.

Options

  • :details is a map of extra diagnostic context. Defaults to %{}.

Returns

Examples

iex> error = Image.Plug.Error.new(:unknown_option, "no such option", details: %{key: "wat"})
iex> error.tag
:unknown_option
iex> error.details
%{key: "wat"}

status(arg1)

@spec status(t() | tag()) :: 100..599

Maps an error tag to a default HTTP status code.

Arguments

Returns

  • An integer HTTP status code.

Examples

iex> Image.Plug.Error.status(:variant_not_found)
404

iex> Image.Plug.Error.status(Image.Plug.Error.new(:invalid_option, "bad"))
400

iex> Image.Plug.Error.status(:internal)
500