mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
404 and 500 drafts
This commit is contained in:
@@ -3,21 +3,48 @@ defmodule ChesstrainerWeb.ErrorHTML do
|
||||
This module is invoked by your endpoint in case of errors on HTML requests.
|
||||
|
||||
See config/config.exs.
|
||||
|
||||
Error templates are rendered outside the root layout, so `404.html.heex` and
|
||||
`500.html.heex` each render a complete document. They share the body markup
|
||||
through `error_page/1`, which the catch-all 404 route also uses.
|
||||
"""
|
||||
use ChesstrainerWeb, :html
|
||||
|
||||
# If you want to customize your error pages,
|
||||
# uncomment the embed_templates/1 call below
|
||||
# and add pages to the error directory:
|
||||
#
|
||||
# * lib/chesstrainer_web/controllers/error_html/404.html.heex
|
||||
# * lib/chesstrainer_web/controllers/error_html/500.html.heex
|
||||
#
|
||||
# embed_templates "error_html/*"
|
||||
embed_templates "error_html/*"
|
||||
|
||||
# The default is to render a plain text page based on
|
||||
# the template name. For example, "404.html" becomes
|
||||
# "Not Found".
|
||||
@doc """
|
||||
The body shared by the standalone error pages and the catch-all 404 route.
|
||||
|
||||
Rendered inside the root layout by `PageController.not_found/2`, and directly
|
||||
by the `ErrorHTML` templates, which bypass layouts.
|
||||
"""
|
||||
attr :status, :integer, required: true
|
||||
attr :title, :string, required: true
|
||||
attr :message, :string, required: true
|
||||
attr :hint, :string, default: nil
|
||||
attr :puzzles, :boolean, default: true
|
||||
|
||||
def error_page(assigns) do
|
||||
~H"""
|
||||
<main class="error-page">
|
||||
<span class="error-code">{@status}</span>
|
||||
<h1>{@title}</h1>
|
||||
<p>{@message}</p>
|
||||
<p :if={@hint} class="error-hint">{@hint}</p>
|
||||
|
||||
<div class="error-actions">
|
||||
<.pill_button variant={:primary} href={~p"/"}>
|
||||
Back to home <.icon_arrow />
|
||||
</.pill_button>
|
||||
<.pill_button :if={@puzzles} variant={:light} href={~p"/endgames"}>
|
||||
Browse puzzles
|
||||
</.pill_button>
|
||||
</div>
|
||||
</main>
|
||||
"""
|
||||
end
|
||||
|
||||
# Statuses without a template keep the previous plain-text behaviour.
|
||||
def render(template, _assigns) do
|
||||
Phoenix.Controller.status_message_from_template(template)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user