mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Show exceptions rescues the original exception
[#5784 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
0d33332571
commit
dde54f00c6
2 changed files with 33 additions and 0 deletions
|
@ -62,6 +62,7 @@ module ActionDispatch
|
|||
private
|
||||
def render_exception(env, exception)
|
||||
log_error(exception)
|
||||
exception = original_exception(exception)
|
||||
|
||||
request = Request.new(env)
|
||||
if @consider_all_requests_local || request.local?
|
||||
|
@ -154,5 +155,17 @@ module ActionDispatch
|
|||
def logger
|
||||
defined?(Rails.logger) ? Rails.logger : Logger.new($stderr)
|
||||
end
|
||||
|
||||
def original_exception(exception)
|
||||
if registered_original_exception?(exception)
|
||||
exception.original_exception
|
||||
else
|
||||
exception
|
||||
end
|
||||
end
|
||||
|
||||
def registered_original_exception?(exception)
|
||||
exception.respond_to?(:original_exception) && @@rescue_responses.has_key?(exception.original_exception.class.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'abstract_unit'
|
||||
|
||||
class ShowExceptionsTest < ActionDispatch::IntegrationTest
|
||||
|
||||
Boomer = lambda do |env|
|
||||
req = ActionDispatch::Request.new(env)
|
||||
case req.path
|
||||
|
@ -12,6 +13,8 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
|
|||
raise ActionController::NotImplemented
|
||||
when "/unprocessable_entity"
|
||||
raise ActionController::InvalidAuthenticityToken
|
||||
when "/not_found_original_exception"
|
||||
raise ActionView::Template::Error.new('template', {}, AbstractController::ActionNotFound.new)
|
||||
else
|
||||
raise "puke!"
|
||||
end
|
||||
|
@ -101,4 +104,21 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
|
|||
assert_response 500
|
||||
assert_match(""foo"=>"[FILTERED]"", body)
|
||||
end
|
||||
|
||||
test "show registered original exception for wrapped exceptions when consider_all_requests_local is false" do
|
||||
@app = ProductionApp
|
||||
self.remote_addr = '208.77.188.166'
|
||||
|
||||
get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true}
|
||||
assert_response 404
|
||||
assert_match(/404 error/, body)
|
||||
end
|
||||
|
||||
test "show registered original exception for wrapped exceptions when consider_all_requests_local is true" do
|
||||
@app = DevelopmentApp
|
||||
|
||||
get "/not_found_original_exception", {}, {'action_dispatch.show_exceptions' => true}
|
||||
assert_response 404
|
||||
assert_match(/AbstractController::ActionNotFound/, body)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue