I created the
500.html.eex templates which seem to be automatically correctly displayed when a 404 or 500 error occurs by the Phoenix framework.
But how can I manually display these templates in some part of my code?
E.g. how should I transform this code, which currently just sends the “not found” text to the browser:
conn |> put_status(404) |> text("not found") |> halt()
to show my custom 404 template?
I think you need to use the app error_view with its render function.
Here is a helper that you could call for the purpose:
def render_error(conn, status) do
Of course for each status you have to define
templates/error folder and its
render function in the
ErrorView. But I think you’ve already done that for 404 and 500 status, otherwise they won’t be automatically displayed as you said.