diff options
author | Jorge Bejar <jorge@wyeworks.com> | 2015-07-20 16:38:09 -0300 |
---|---|---|
committer | Jorge Bejar <jorge@wyeworks.com> | 2015-12-09 10:53:45 -0300 |
commit | 6fa2023c816e8dc8d2735a5fe87098ef5d8253f9 (patch) | |
tree | efa9a44d6ef690d2be21629cb4663524c3334494 | |
parent | 668d94fff644e87d49004e4f48143f5561e8c9a0 (diff) | |
download | rails-6fa2023c816e8dc8d2735a5fe87098ef5d8253f9.tar.gz rails-6fa2023c816e8dc8d2735a5fe87098ef5d8253f9.tar.bz2 rails-6fa2023c816e8dc8d2735a5fe87098ef5d8253f9.zip |
DebugException initialize with a response_format value
3 files changed, 10 insertions, 9 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 7912b5ce82..642c7183cc 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -38,10 +38,10 @@ module ActionDispatch end end - def initialize(app, routes_app = nil, api_only = false) - @app = app - @routes_app = routes_app - @api_only = api_only + def initialize(app, routes_app = nil, response_format = :default) + @app = app + @routes_app = routes_app + @response_format = response_format end def call(env) @@ -67,9 +67,10 @@ module ActionDispatch log_error(request, wrapper) if request.get_header('action_dispatch.show_detailed_exceptions') - if @api_only + case @response_format + when :api render_for_api_application(request, wrapper) - else + when :default render_for_default_application(request, wrapper) end else diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index d9c6233511..159bf10545 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -213,7 +213,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end test "rescue with json error for API request" do - @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, true) + @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api) get "/", headers: { 'action_dispatch.show_exceptions' => true } assert_response 500 @@ -254,7 +254,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end test "rescue with json on API request returns only allowed formats or json as a fallback" do - @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, true) + @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api) get "/index.json", headers: { 'action_dispatch.show_exceptions' => true } assert_response 500 diff --git a/railties/lib/rails/application/default_middleware_stack.rb b/railties/lib/rails/application/default_middleware_stack.rb index 9201395091..ed6a1f82d3 100644 --- a/railties/lib/rails/application/default_middleware_stack.rb +++ b/railties/lib/rails/application/default_middleware_stack.rb @@ -57,7 +57,7 @@ module Rails # Must come after Rack::MethodOverride to properly log overridden methods middleware.use ::Rails::Rack::Logger, config.log_tags middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app - middleware.use ::ActionDispatch::DebugExceptions, app, config.api_only + middleware.use ::ActionDispatch::DebugExceptions, app, config.debug_exception_response_format middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies unless config.cache_classes |