1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

move show_detailed_exceptions? to Rescue module

This commit is contained in:
lest 2011-11-22 13:34:13 +03:00
parent c6d6b28bb4
commit 5bcd119b8d
4 changed files with 14 additions and 7 deletions

View file

@ -196,15 +196,10 @@ module ActionController
@_request = request @_request = request
@_env = request.env @_env = request.env
@_env['action_controller.instance'] = self @_env['action_controller.instance'] = self
@_env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions?
process(name) process(name)
to_a to_a
end end
def show_detailed_exceptions?
defined?(Rails.application) && Rails.application.config.consider_all_requests_local || request.local?
end
def to_a #:nodoc: def to_a #:nodoc:
response ? response.to_a : [status, headers, response_body] response ? response.to_a : [status, headers, response_body]
end end

View file

@ -3,6 +3,11 @@ module ActionController #:nodoc:
extend ActiveSupport::Concern extend ActiveSupport::Concern
include ActiveSupport::Rescuable include ActiveSupport::Rescuable
included do
config_accessor :consider_all_requests_local
self.consider_all_requests_local = false if consider_all_requests_local.nil?
end
def rescue_with_handler(exception) def rescue_with_handler(exception)
if (exception.respond_to?(:original_exception) && if (exception.respond_to?(:original_exception) &&
(orig_exception = exception.original_exception) && (orig_exception = exception.original_exception) &&
@ -12,10 +17,15 @@ module ActionController #:nodoc:
super(exception) super(exception)
end end
def show_detailed_exceptions?
consider_all_requests_local || request.local?
end
private private
def process_action(*args) def process_action(*args)
super super
rescue Exception => exception rescue Exception => exception
request.env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions?
rescue_with_handler(exception) || raise(exception) rescue_with_handler(exception) || raise(exception)
end end
end end

View file

@ -21,6 +21,8 @@ module ActionController
paths = app.config.paths paths = app.config.paths
options = app.config.action_controller options = app.config.action_controller
options.consider_all_requests_local ||= app.config.consider_all_requests_local
options.assets_dir ||= paths["public"].first options.assets_dir ||= paths["public"].first
options.javascripts_dir ||= paths["public/javascripts"].first options.javascripts_dir ||= paths["public/javascripts"].first
options.stylesheets_dir ||= paths["public/stylesheets"].first options.stylesheets_dir ||= paths["public/stylesheets"].first

View file

@ -1,7 +1,7 @@
require 'abstract_unit' require 'abstract_unit'
module ShowExceptions module ShowExceptions
class ShowExceptionsController < ActionController::Metal class ShowExceptionsController < ActionController::Base
use ActionDispatch::ShowExceptions use ActionDispatch::ShowExceptions
def boom def boom
@ -27,7 +27,7 @@ module ShowExceptions
end end
test 'show diagnostics from a remote ip when consider_all_requests_local is true' do test 'show diagnostics from a remote ip when consider_all_requests_local is true' do
Rails.stubs(:application).returns stub(:config => stub(:consider_all_requests_local => true)) ShowExceptionsController.any_instance.stubs(:consider_all_requests_local).returns(true)
@app = ShowExceptionsController.action(:boom) @app = ShowExceptionsController.action(:boom)
self.remote_addr = '208.77.188.166' self.remote_addr = '208.77.188.166'
get '/' get '/'