improve error pages: minimal version when site not live
All checks were successful
deploy / deploy (push) Successful in 1m19s
All checks were successful
deploy / deploy (push) Successful in 1m19s
Show a lightweight error page using admin.css when the shop isn't live yet, avoiding broken theme dependencies. Also tidied up copy to sentence case and shorter descriptions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2563338a6a
commit
b06029079d
@ -16,8 +16,8 @@ defmodule BerrypodWeb.ErrorHTML do
|
||||
render_error_page(
|
||||
assigns,
|
||||
"404",
|
||||
"Page Not Found",
|
||||
"Sorry, we couldn't find the page you're looking for. Perhaps you've mistyped the URL or the page has been moved."
|
||||
"Page not found",
|
||||
"Sorry, we couldn't find the page you're looking for."
|
||||
)
|
||||
end
|
||||
|
||||
@ -25,8 +25,8 @@ defmodule BerrypodWeb.ErrorHTML do
|
||||
render_error_page(
|
||||
assigns,
|
||||
"500",
|
||||
"Server Error",
|
||||
"Something went wrong on our end. Please try again later or contact support if the problem persists."
|
||||
"Server error",
|
||||
"Something went wrong on our end. Please try again later."
|
||||
)
|
||||
end
|
||||
|
||||
@ -35,7 +35,44 @@ defmodule BerrypodWeb.ErrorHTML do
|
||||
end
|
||||
|
||||
defp render_error_page(assigns, error_code, error_title, error_description) do
|
||||
# Load theme settings with fallback for error conditions
|
||||
site_live = safe_load(&Settings.site_live?/0) || false
|
||||
|
||||
assigns =
|
||||
assigns
|
||||
|> Map.put(:error_code, error_code)
|
||||
|> Map.put(:error_title, error_title)
|
||||
|> Map.put(:error_description, error_description)
|
||||
|> Map.put(:site_live, site_live)
|
||||
|
||||
if site_live do
|
||||
render_themed_error(assigns)
|
||||
else
|
||||
render_minimal_error(assigns)
|
||||
end
|
||||
end
|
||||
|
||||
defp render_minimal_error(assigns) do
|
||||
~H"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>{@error_code} - {@error_title}</title>
|
||||
<link phx-track-static rel="stylesheet" href={~p"/assets/css/admin.css"} />
|
||||
</head>
|
||||
<body>
|
||||
<main class="setup-page" style="padding-top: 6rem; text-align: center;">
|
||||
<p style="font-size: 3rem; font-weight: 700; margin: 0;">{@error_code}</p>
|
||||
<h1 style="font-size: 1.25rem; font-weight: 600; margin: 0.5rem 0;">{@error_title}</h1>
|
||||
<p style="font-size: 0.875rem; opacity: 0.6;">{@error_description}</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
end
|
||||
|
||||
defp render_themed_error(assigns) do
|
||||
{theme_settings, generated_css} = load_theme_data()
|
||||
logo_image = safe_load(&Media.get_logo/0)
|
||||
header_image = safe_load(&Media.get_header/0)
|
||||
@ -51,9 +88,6 @@ defmodule BerrypodWeb.ErrorHTML do
|
||||
|> Map.put(:header_image, header_image)
|
||||
|> Map.put(:products, products)
|
||||
|> Map.put(:categories, categories)
|
||||
|> Map.put(:error_code, error_code)
|
||||
|> Map.put(:error_title, error_title)
|
||||
|> Map.put(:error_description, error_description)
|
||||
|> Map.put(:mode, :shop)
|
||||
|> Map.put(:cart_items, [])
|
||||
|> Map.put(:cart_count, 0)
|
||||
|
||||
@ -4,17 +4,15 @@ defmodule BerrypodWeb.ErrorHTMLTest do
|
||||
# Bring render_to_string/4 for testing custom views
|
||||
import Phoenix.Template, only: [render_to_string: 4]
|
||||
|
||||
test "renders 404.html with themed page" do
|
||||
test "renders 404.html" do
|
||||
html = render_to_string(BerrypodWeb.ErrorHTML, "404", "html", [])
|
||||
assert html =~ "404"
|
||||
assert html =~ "Page Not Found"
|
||||
assert html =~ "shop-root"
|
||||
assert html =~ "Page not found"
|
||||
end
|
||||
|
||||
test "renders 500.html with themed page" do
|
||||
test "renders 500.html" do
|
||||
html = render_to_string(BerrypodWeb.ErrorHTML, "500", "html", [])
|
||||
assert html =~ "500"
|
||||
assert html =~ "Server Error"
|
||||
assert html =~ "shop-root"
|
||||
assert html =~ "Server error"
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user