aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJorge Bejar <jorge@wyeworks.com>2015-07-06 21:33:19 -0300
committerJorge Bejar <jorge@wyeworks.com>2015-12-09 10:53:41 -0300
commit83b4e9073f0852afc065ef398bd3ad9b5a6db29c (patch)
treedc2f2e814f8c6dcf4a1a0768c58c99e6d295d302 /actionpack/lib
parentb79bfaadaf5b5c6d3e458c24184a0e846bd8cf55 (diff)
downloadrails-83b4e9073f0852afc065ef398bd3ad9b5a6db29c.tar.gz
rails-83b4e9073f0852afc065ef398bd3ad9b5a6db29c.tar.bz2
rails-83b4e9073f0852afc065ef398bd3ad9b5a6db29c.zip
Response when error should be formatted properly in Rails API if local request
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/http/parameters.rb6
-rw-r--r--actionpack/lib/action_dispatch/middleware/debug_exceptions.rb17
2 files changed, 18 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb
index 5c20bc53c2..4084d78f49 100644
--- a/actionpack/lib/action_dispatch/http/parameters.rb
+++ b/actionpack/lib/action_dispatch/http/parameters.rb
@@ -69,15 +69,15 @@ module ActionDispatch
def default_path_parameters
if format = format_from_path_extension
- { 'format' => format }
+ { format: format }
else
{}
end
end
def format_from_path_extension
- path = @env['action_dispatch.original_path']
- if match = path.match(/\.(\w+)$/)
+ path = @env['action_dispatch.original_path'] || @env['PATH_INFO']
+ if match = path && path.match(/\.(\w+)$/)
match.captures.first
end
end
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