Reputation: 3982
I know that Phoenix can handle the error response and render the related error page. But I would like to visit the 500.html.eex
manually by http://localhost:4000/500.html
. Is there any good way to do it instead of add new controller?
The reason I do this, is that I have js method to check stuff, and redirect to error page if failed.
Cheers
Upvotes: 1
Views: 1177
Reputation: 131
For the sake of temporarily viewing the 500 error page, to test it and such, I would tweak the program to redirect 404 errors to the 500 page by customising MyApp.ErrorView
.
In this module, just change (or add):
def render("404.html", _assigns) do
...
end
to this:
def render("404.html", _assigns) do
render("500.html", assigns)
end
Then, in config/dev.exs
change the web endpoint configuration so that debug_errors
is set to false
:
config :my_app, MyAppWeb.Endpoint,
# http: [port: 8000],
debug_errors: false
Then proceed to a random url: localhost:8000/somerandomurl
to view your 500.html
error page.
Here, your 500.html.eex
page should show. Let me know if you require a more complex tweak.
Upvotes: 2
Reputation: 301
You should build the controller and route for it, so that you can just redirect to that URL.
Upvotes: 0