Skip to content

Commit cde2bd9

Browse files
committed
Ignore the root layout on error pages
1 parent 53d5362 commit cde2bd9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/phoenix/endpoint/render_errors.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ defmodule Phoenix.Endpoint.RenderErrors do
106106
|> maybe_fetch_query_params()
107107
|> maybe_fetch_format(opts)
108108
|> Plug.Conn.put_status(status)
109+
|> Controller.put_root_layout(opts[:root_layout] || false)
109110
|> Controller.put_layout(opts[:layout] || false)
110111
|> Controller.put_view(view)
111112

test/phoenix/endpoint/render_errors_test.exs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ defmodule Phoenix.Endpoint.RenderErrorsTest do
77
import ExUnit.CaptureLog
88
view = __MODULE__
99

10-
def render("app.html", %{view_template: view_template} = assigns) do
11-
"Layout: " <> render(view_template, assigns)
10+
def render("app.html", assigns) do
11+
"Layout: " <> (Map.get(assigns, :inner_content) || render(assigns.view_template, assigns))
1212
end
1313

1414
def render("404.html", %{kind: kind, reason: _reason, stack: _stack, status: 404, conn: conn}) do
@@ -56,6 +56,12 @@ defmodule Phoenix.Endpoint.RenderErrorsTest do
5656
_ -> System.stacktrace()
5757
end
5858

59+
# Those are always ignored and must be explicitly opted-in.
60+
conn =
61+
conn
62+
|> Phoenix.Controller.put_layout({Unknown, "layout"})
63+
|> Phoenix.Controller.put_root_layout({Unknown, "root"})
64+
5965
reason = ArgumentError.exception("oops")
6066
raise Plug.Conn.WrapperError, conn: conn, kind: :error, stack: stack, reason: reason
6167
end
@@ -252,6 +258,14 @@ defmodule Phoenix.Endpoint.RenderErrorsTest do
252258
assert body == "Layout: Got 500 from throw with GET"
253259
end
254260

261+
test "exception page with root layout" do
262+
body = assert_render(500, conn(:get, "/"), [root_layout: {__MODULE__, :app}], fn ->
263+
throw :hello
264+
end)
265+
266+
assert body == "Layout: Got 500 from throw with GET"
267+
end
268+
255269
test "exception page is shown even with invalid format" do
256270
conn = conn(:get, "/") |> put_req_header("accept", "unknown/unknown")
257271
body = assert_render(500, conn, [], fn -> throw :hello end)

0 commit comments

Comments
 (0)