show proper 404 page for missing custom pages instead of redirecting
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,23 +15,13 @@ defmodule BerrypodWeb.Shop.CustomPage do
|
||||
cond do
|
||||
is_nil(page) ->
|
||||
record_broken_url("/#{slug}")
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, "Page not found")
|
||||
|> push_navigate(to: ~p"/")}
|
||||
raise BerrypodWeb.NotFoundError
|
||||
|
||||
page.type != "custom" ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, "Page not found")
|
||||
|> push_navigate(to: ~p"/")}
|
||||
raise BerrypodWeb.NotFoundError
|
||||
|
||||
page.published != true and not socket.assigns.is_admin ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:error, "Page not found")
|
||||
|> push_navigate(to: ~p"/")}
|
||||
raise BerrypodWeb.NotFoundError
|
||||
|
||||
true ->
|
||||
extra = Pages.load_block_data(page.blocks, socket.assigns)
|
||||
|
||||
10
lib/berrypod_web/not_found_error.ex
Normal file
10
lib/berrypod_web/not_found_error.ex
Normal file
@@ -0,0 +1,10 @@
|
||||
defmodule BerrypodWeb.NotFoundError do
|
||||
@moduledoc """
|
||||
Raised in LiveViews when a resource can't be found.
|
||||
|
||||
Implements `Plug.Exception` so Phoenix renders the 404 error page
|
||||
instead of a 500.
|
||||
"""
|
||||
|
||||
defexception message: "not found", plug_status: 404
|
||||
end
|
||||
Reference in New Issue
Block a user