Stephen
Stephen

Reputation: 3982

How to manually visit 500 error page in phoenix?

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

Answers (2)

Peter S.
Peter S.

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

Kalvin Hom
Kalvin Hom

Reputation: 301

You should build the controller and route for it, so that you can just redirect to that URL.

Upvotes: 0

Related Questions