PhoenixKitStaff.Errors (PhoenixKitStaff v0.2.0)

Copy Markdown View Source

Atom → translated-string dispatcher for Staff context errors.

Context functions return {:error, atom} (or {:error, %Ecto.Changeset{}} for changeset errors); LiveViews call Errors.message/1 at the presentation boundary to translate the atom into a flash-ready user-facing string.

Keeping the dispatcher here means:

  1. Translation files only need to know about the literal strings in this module — the gettext extractor sees the literals at the gettext(...) call site of each branch.
  2. Context functions stay storage-agnostic (no gettext calls in lib/phoenix_kit_staff/staff.ex); LiveViews are the one place that turns intent into copy.
  3. Future changes to wording happen in one place; new error conditions get a new atom + a new branch here.

Summary

Types

Atoms that the Staff context returns inside {:error, atom} tuples. Adding a new atom requires adding a message/1 branch below — the not_found fallback then never fires for known shapes.

Functions

Translates a Staff error atom into a user-facing message.

Types

error_atom()

@type error_atom() ::
  :blank_email
  | :placeholder_already_claimed
  | :email_already_taken
  | :not_found

Atoms that the Staff context returns inside {:error, atom} tuples. Adding a new atom requires adding a message/1 branch below — the not_found fallback then never fires for known shapes.

Functions

message(other)

@spec message(error_atom() | atom()) :: String.t()

Translates a Staff error atom into a user-facing message.

Defaults to a generic fallback for unknown atoms so that callers always get a renderable string (no raised pattern-match) — but a fallback that fires in production is a sign that a context fn returned an atom this module doesn't know about, and should be added here.