lib/action_dispatch/middleware/show_exceptions.rb in actionpack-7.1.3.4 vs lib/action_dispatch/middleware/show_exceptions.rb in actionpack-7.1.4
- old
+ new
@@ -31,21 +31,23 @@
@app.call(env)
rescue Exception => exception
request = ActionDispatch::Request.new env
backtrace_cleaner = request.get_header("action_dispatch.backtrace_cleaner")
wrapper = ExceptionWrapper.new(backtrace_cleaner, exception)
+ request.set_header "action_dispatch.exception", wrapper.unwrapped_exception
+ request.set_header "action_dispatch.report_exception", !wrapper.rescue_response?
+
if wrapper.show?(request)
- render_exception(request, wrapper)
+ render_exception(request.dup, wrapper)
else
raise exception
end
end
private
def render_exception(request, wrapper)
status = wrapper.status_code
- request.set_header "action_dispatch.exception", wrapper.unwrapped_exception
request.set_header "action_dispatch.original_path", request.path_info
request.set_header "action_dispatch.original_request_method", request.raw_request_method
fallback_to_html_format_if_invalid_mime_type(request)
request.path_info = "/#{status}"
request.request_method = "GET"
@@ -63,12 +65,20 @@
def fallback_to_html_format_if_invalid_mime_type(request)
# If the MIME type for the request is invalid then the
# @exceptions_app may not be able to handle it. To make it
# easier to handle, we switch to HTML.
- request.formats
- rescue ActionDispatch::Http::MimeNegotiation::InvalidType
- request.set_header "HTTP_ACCEPT", "text/html"
+ begin
+ request.content_mime_type
+ rescue ActionDispatch::Http::MimeNegotiation::InvalidType
+ request.set_header "CONTENT_TYPE", "text/html"
+ end
+
+ begin
+ request.formats
+ rescue ActionDispatch::Http::MimeNegotiation::InvalidType
+ request.set_header "HTTP_ACCEPT", "text/html"
+ end
end
def pass_response(status)
[status, { Rack::CONTENT_TYPE => "text/html; charset=#{Response.default_charset}",
Rack::CONTENT_LENGTH => "0" }, []]