Inspecting the response headers, this is not visible to the end-user.
Which purpose does this bit of code serve?
I am setting up a custom exceptions app that changes behavior based on the path and this tripped me up.
I did some digging, because I had a hunch. #render_exception is called here:
if wrapper.show?(request)
render_exception(request.dup, wrapper)
else
raise exception
end
and ActionDispatch::ExceptionWrapper#show? :
def show?(request)
# We're treating `nil` as "unset", and we want the default setting to be `:all`.
# This logic should be extracted to `env_config` and calculated once.
config = request.get_header("action_dispatch.show_exceptions")
case config
when :none
false
when :rescuable
rescue_response?
else
true
end
end
And I can’t find config.action_dispatch.show_exceptions config set (in my repo at least), but I’m guessing on production it would be nil (which the comment suggests should be treated as :none),
So it probably has something to do with the case when, on your dev env, you submit (POST) a form and hit an exception—we show a page with the exception details.
And here I hit the limits of my understanding, and can just say it might be important for some reason in this case for the request to “think” it’s “GET.” But I don’t know how this would influence the framework behavior down the road. (An my coffee break is over, so can’t dig deeper ATM).
Thanks for digging, one thing that came to my mind is that maybe this is required for using the routes as exceptions_app, like config.exceptions_app = Rails.application.routes
I’ve seen some examples where people have implemented explicit routes for their exceptions, f.e.
get "404", to: "errors#not_found"
I think if the path (and sometimes verb) were left unchanged, this approach would not work. So I guess it is the “intended” way to define routes for custom exceptions, since the change is hardcoded and is not based on the actual exceptions_app that is used. Otherwise it’d have to be wrapped in a conditional:
...
if @exceptions_app.is_a?(Rails::Engine::LazyRouteSet)
request.path_info = "/#{status}"
request.request_method = "GET"
end
response = @exceptions_app.call(request.env)
...
However, using the routes for exception pages has a smell in my book, since error pages can be accessed at will in that case and cannot be presented in the context of the actual Controller that raised.