GamendWeb.ErrorHTML (gamend_web v1.0.1216)

Copy Markdown View Source

Error pages for HTML requests.

Phoenix's default renders the status message as plain text — a 404 was nine bytes reading "Not Found", which looks like the whole site is broken rather than one URL being wrong, and gives a reader nowhere to go but Back.

render_errors is configured layout: false, so these templates are whole documents. That is the right shape for them anyway: this page has to render when something has already failed, so it depends on no layout, no asset bundle and no assign the endpoint might not have set. Styling is inline — the browser CSP permits inline styles but not inline scripts, so there is also no JS.

Locale-aware where it can be: the LocalePath plug has usually already run and set the gettext locale, so the copy is translated and the links keep the reader's language prefix. Where it has not (an error early in the pipeline), it falls back to the default locale rather than raising — the one thing an error page must never do is fail.

Summary

Functions

Extra places to send a lost reader, beyond Home.

Renders an error page for a status template such as "404.html".

Functions

error_page(assigns)

links(assigns \\ %{})

Extra places to send a lost reader, beyond Home.

Core has no idea what a given host's pages are called — /vocabulary means nothing to a Gamend server that is not this one — so the list is empty by default and each host names its own:

config :gamend_web, :error_page_links, [
  %{label: "Vocabulary", path: "vocabulary"},
  %{label: "Play", path: "play"}
]

path is relative and gets the reader's locale prefix, so from /fr/nope the links stay French. Labels are looked up in the host's gettext catalogue at render time; they resolve when the msgid already exists there (these are navigation labels, so it generally does) and fall back to the literal otherwise.

An :error_page_links assign wins over the application env, so a caller (or a test) can pin the list for one render without touching global config.

render(template, assigns)

Renders an error page for a status template such as "404.html".

Anything without copy of its own falls through to the generic page rather than to Phoenix's plain-text default, so no status can render as a bare string.