You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Routing errors are converted into generic 404 responses then sent up the
middleware stack as a normal response. One thing to note is that they
include a special `X-Cascade` error.
Supposedly, [this header](http://stackoverflow.com/a/5644114/47438) is
meant to indicate that other middleware can inspect and try to handle
the route. This allows gems like `devise` to have default routes for
sign in and sign up configured, but still lets the application create
custom routes if it wants.
Since this is our error handler, it is the place to stop the chain and
raise an appropriate routing error. We could simply toggle on the header
and call our `render_json_error` in the `if` block, but by using the
error it hooks directly into our existing logic - no need to duplicate
it. It also means we can register the routing error with our public
exceptions or standard error handler without worrying about special edge
cases. Finally, by raising an error it properly represents the fact that
this was a routing error. BTW this is the strategy that Rails itself
uses.
0 commit comments