2026-02-18 21:23:15 +00:00
|
|
|
defmodule BerrypodWeb.ErrorHTML do
|
2025-12-30 12:26:26 +00:00
|
|
|
@moduledoc """
|
|
|
|
|
This module is invoked by your endpoint in case of errors on HTML requests.
|
|
|
|
|
|
|
|
|
|
See config/config.exs.
|
|
|
|
|
"""
|
2026-02-18 21:23:15 +00:00
|
|
|
use BerrypodWeb, :html
|
2025-12-30 12:26:26 +00:00
|
|
|
|
2026-02-18 21:23:15 +00:00
|
|
|
alias Berrypod.Settings
|
|
|
|
|
alias Berrypod.Settings.ThemeSettings
|
|
|
|
|
alias Berrypod.Media
|
|
|
|
|
alias Berrypod.Products
|
|
|
|
|
alias Berrypod.Theme.{CSSCache, CSSGenerator}
|
2026-01-17 22:29:45 +00:00
|
|
|
|
|
|
|
|
def render("404.html", assigns) do
|
2026-01-31 14:24:58 +00:00
|
|
|
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."
|
|
|
|
|
)
|
2026-01-17 22:29:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def render("500.html", assigns) do
|
2026-01-31 14:24:58 +00:00
|
|
|
render_error_page(
|
|
|
|
|
assigns,
|
|
|
|
|
"500",
|
|
|
|
|
"Server Error",
|
|
|
|
|
"Something went wrong on our end. Please try again later or contact support if the problem persists."
|
|
|
|
|
)
|
2026-01-17 22:29:45 +00:00
|
|
|
end
|
|
|
|
|
|
2025-12-30 12:26:26 +00:00
|
|
|
def render(template, _assigns) do
|
|
|
|
|
Phoenix.Controller.status_message_from_template(template)
|
|
|
|
|
end
|
2026-01-17 22:29:45 +00:00
|
|
|
|
|
|
|
|
defp render_error_page(assigns, error_code, error_title, error_description) do
|
|
|
|
|
# Load theme settings with fallback for error conditions
|
|
|
|
|
{theme_settings, generated_css} = load_theme_data()
|
|
|
|
|
logo_image = safe_load(&Media.get_logo/0)
|
|
|
|
|
header_image = safe_load(&Media.get_header/0)
|
|
|
|
|
|
2026-02-13 08:27:26 +00:00
|
|
|
products = safe_load(fn -> Products.list_visible_products(limit: 4) end) || []
|
|
|
|
|
categories = safe_load(fn -> Products.list_categories() end) || []
|
2026-01-17 22:29:45 +00:00
|
|
|
|
|
|
|
|
assigns =
|
|
|
|
|
assigns
|
|
|
|
|
|> Map.put(:theme_settings, theme_settings)
|
|
|
|
|
|> Map.put(:generated_css, generated_css)
|
|
|
|
|
|> Map.put(:logo_image, logo_image)
|
|
|
|
|
|> Map.put(:header_image, header_image)
|
2026-02-13 08:27:26 +00:00
|
|
|
|> Map.put(:products, products)
|
|
|
|
|
|> Map.put(:categories, categories)
|
2026-01-17 22:29:45 +00:00
|
|
|
|> 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)
|
|
|
|
|
|> Map.put(:cart_subtotal, "£0.00")
|
|
|
|
|
|
|
|
|
|
~H"""
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en" class="h-full">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
2026-01-31 14:24:58 +00:00
|
|
|
<title>{@error_code} - {@error_title}</title>
|
2026-02-20 22:02:07 +00:00
|
|
|
<link phx-track-static rel="stylesheet" href={~p"/assets/css/shop.css"} />
|
2026-01-17 22:29:45 +00:00
|
|
|
<style id="theme-css">
|
|
|
|
|
<%= Phoenix.HTML.raw(@generated_css) %>
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body class="h-full">
|
2026-01-31 14:24:58 +00:00
|
|
|
<div
|
|
|
|
|
class="shop-root themed h-full"
|
|
|
|
|
data-mood={@theme_settings.mood}
|
|
|
|
|
data-typography={@theme_settings.typography}
|
|
|
|
|
data-shape={@theme_settings.shape}
|
|
|
|
|
data-density={@theme_settings.density}
|
|
|
|
|
data-grid={@theme_settings.grid_columns}
|
|
|
|
|
data-header={@theme_settings.header_layout}
|
|
|
|
|
data-sticky={to_string(@theme_settings.sticky_header)}
|
|
|
|
|
data-layout={@theme_settings.layout_width}
|
|
|
|
|
data-shadow={@theme_settings.card_shadow}
|
|
|
|
|
>
|
2026-02-18 21:23:15 +00:00
|
|
|
<BerrypodWeb.PageTemplates.error
|
2026-01-17 22:29:45 +00:00
|
|
|
theme_settings={@theme_settings}
|
|
|
|
|
logo_image={@logo_image}
|
|
|
|
|
header_image={@header_image}
|
2026-02-13 08:27:26 +00:00
|
|
|
products={@products}
|
|
|
|
|
categories={@categories}
|
2026-01-17 22:29:45 +00:00
|
|
|
error_code={@error_code}
|
|
|
|
|
error_title={@error_title}
|
|
|
|
|
error_description={@error_description}
|
|
|
|
|
mode={@mode}
|
|
|
|
|
cart_items={@cart_items}
|
|
|
|
|
cart_count={@cart_count}
|
|
|
|
|
cart_subtotal={@cart_subtotal}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
"""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp load_theme_data do
|
|
|
|
|
try do
|
|
|
|
|
theme_settings = Settings.get_theme_settings()
|
2026-01-31 14:24:58 +00:00
|
|
|
|
2026-01-17 22:29:45 +00:00
|
|
|
generated_css =
|
|
|
|
|
case CSSCache.get() do
|
2026-01-31 14:24:58 +00:00
|
|
|
{:ok, css} ->
|
|
|
|
|
css
|
|
|
|
|
|
2026-01-17 22:29:45 +00:00
|
|
|
:miss ->
|
2026-02-20 18:39:41 +00:00
|
|
|
css = CSSGenerator.generate(theme_settings, &BerrypodWeb.Endpoint.static_path/1)
|
2026-01-17 22:29:45 +00:00
|
|
|
CSSCache.put(css)
|
|
|
|
|
css
|
|
|
|
|
end
|
2026-01-31 14:24:58 +00:00
|
|
|
|
2026-01-17 22:29:45 +00:00
|
|
|
{theme_settings, generated_css}
|
|
|
|
|
rescue
|
|
|
|
|
_ -> {%ThemeSettings{}, ""}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp safe_load(fun) do
|
|
|
|
|
try do
|
|
|
|
|
fun.()
|
|
|
|
|
rescue
|
|
|
|
|
_ -> nil
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-12-30 12:26:26 +00:00
|
|
|
end
|