diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/debug_exceptions.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 66bb74b9c5..972410d806 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -38,9 +38,10 @@ module ActionDispatch end end - def initialize(app, routes_app = nil) + def initialize(app, routes_app = nil, api_only = false) @app = app @routes_app = routes_app + @api_only = api_only end def call(env) @@ -90,7 +91,19 @@ module ActionDispatch ) file = "rescues/#{wrapper.rescue_template}" - if request.xhr? + if @api_only + body = { + :status => wrapper.status_code, + :error => Rack::Utils::HTTP_STATUS_CODES.fetch(wrapper.status_code, Rack::Utils::HTTP_STATUS_CODES[500]), + :exception => wrapper.exception.inspect, + :traces => traces + } + if content_type = request.formats.first + to_format = "to_#{content_type.to_sym}" + body = body.public_send(to_format) + end + format = "application/json" + elsif request.xhr? body = template.render(template: file, layout: false, formats: [:text]) format = "text/plain" else |