Fix 404 errors showing up as 500 errors #4774
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4765 .
First off, note that this error can only be reproduced on local if you change
in
development.rb
tofalse
.The reason that a redirect to
/404
happens is because of this line in application.rb:This forwards the error logic to the router, which redirects to a route that matches e.g.
/404
. When this happens, we lose all information about the route that couldn't be found. We also end up with a very bad-looking 500 error if the user isn't logged in.I've removed this line so that Rails goes back to the default path of showing the file in
public/404.html
etc. I copy-pasted the end result of the current logic to show the static page that shows up regardless of whether the user is logged in or not. Sample for 500 below.