I'm trying to access the assigns after a Custom Error View renders an error caught by the phoenix server.
My problem is that the assigns attributes are not coming over. My specific issue is that the functions used for home page navigation think the user is logged out, due to the absence of the assigns map.
I don't think there is extra implementation steps for custom error templates, and that this stuff is autogenerated at the beginning of a project, but the documentation is found here.
My error_view.ex
:
defmodule FulfillmentCartWeb.ErrorView do
use FulfillmentCartWeb, :view
def render("404.html", _assigns) do
IO.inspect(_assigns)
"Internal Server Error"
end
def template_not_found(template, _assigns) do
Phoenix.Controller.status_message_from_template(template)
end
end
My dev.exs
endpoint:
config :fulfillment_cart, FulfillmentCartWeb.Endpoint,
http: [port: 4000],
debug_errors: false,
code_reloader: true,
check_origin: false,
watchers: [
node: [
"node_modules/webpack/bin/webpack.js",
"--mode",
"development",
"--watch-stdin",
cd: Path.expand("../assets", __DIR__)
]
]
Force a 404 error by visiting a route that is going to throw Phoenix's
NoRouteError
.Use the customized error view to catch that 404 error and get some output.
See response as:
reason: %Phoenix.Router.NoRouteError{
conn: %Plug.Conn{
adapter: {Plug.Cowboy.Conn, :...},
assigns: %{},
....................
}
}
Now you can see why this is a problem, I need my assigns in order to validate the user is logged in or really have any data previously saved in the connection object, such as :plug_session
variables.
Why is it that my assigns is being thrown out in the trashcan whenever I try to catch a custom error? Is it something with the ulterior design of HTTP? Is this even Phoenix? Am I even permitted to have connection information when the server errors a 404?