aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2016-05-11 11:13:35 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2016-05-11 11:13:35 -0300
commit5f7d3363c5b6fc3b5e8261539a420c88ddde71a5 (patch)
tree2ce1723f64011e9c9cb08852c156905a5ba929b7 /actionpack/lib
parent733161d48b4292c8731c35eaa20131a49c5a5b9a (diff)
parentc33bda875e562561292eafc7c99362f23cf8150a (diff)
downloadrails-5f7d3363c5b6fc3b5e8261539a420c88ddde71a5.tar.gz
rails-5f7d3363c5b6fc3b5e8261539a420c88ddde71a5.tar.bz2
rails-5f7d3363c5b6fc3b5e8261539a420c88ddde71a5.zip
Merge pull request #24912 from prathamesh-sonpatki/api-fix-response-format
API only apps: Preserve request format for HTML requests too
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/middleware/debug_exceptions.rb20
1 files changed, 12 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
index 51a471fb23..5f758d641a 100644
--- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
@@ -67,18 +67,19 @@ module ActionDispatch
log_error(request, wrapper)
if request.get_header('action_dispatch.show_detailed_exceptions')
- case @response_format
- when :api
- render_for_api_application(request, wrapper)
- when :default
- render_for_default_application(request, wrapper)
+ content_type = request.formats.first
+
+ if api_request?(content_type)
+ render_for_api_request(content_type, wrapper)
+ else
+ render_for_browser_request(request, wrapper)
end
else
raise exception
end
end
- def render_for_default_application(request, wrapper)
+ def render_for_browser_request(request, wrapper)
template = create_template(request, wrapper)
file = "rescues/#{wrapper.rescue_template}"
@@ -92,7 +93,7 @@ module ActionDispatch
render(wrapper.status_code, body, format)
end
- def render_for_api_application(request, wrapper)
+ def render_for_api_request(content_type, wrapper)
body = {
status: wrapper.status_code,
error: Rack::Utils::HTTP_STATUS_CODES.fetch(
@@ -103,7 +104,6 @@ module ActionDispatch
traces: wrapper.traces
}
- content_type = request.formats.first
to_format = "to_#{content_type.to_sym}"
if content_type && body.respond_to?(to_format)
@@ -181,5 +181,9 @@ module ActionDispatch
ActionDispatch::Routing::RoutesInspector.new(@routes_app.routes.routes)
end
end
+
+ def api_request?(content_type)
+ @response_format == :api && !content_type.html?
+ end
end
end