Skip to content

Commit 5bcd119

Browse files
committed
move show_detailed_exceptions? to Rescue module
1 parent c6d6b28 commit 5bcd119

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

actionpack/lib/action_controller/metal.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,10 @@ def dispatch(name, request) #:nodoc:
196196
@_request = request
197197
@_env = request.env
198198
@_env['action_controller.instance'] = self
199-
@_env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions?
200199
process(name)
201200
to_a
202201
end
203202

204-
def show_detailed_exceptions?
205-
defined?(Rails.application) && Rails.application.config.consider_all_requests_local || request.local?
206-
end
207-
208203
def to_a #:nodoc:
209204
response ? response.to_a : [status, headers, response_body]
210205
end

actionpack/lib/action_controller/metal/rescue.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ module Rescue
33
extend ActiveSupport::Concern
44
include ActiveSupport::Rescuable
55

6+
included do
7+
config_accessor :consider_all_requests_local
8+
self.consider_all_requests_local = false if consider_all_requests_local.nil?
9+
end
10+
611
def rescue_with_handler(exception)
712
if (exception.respond_to?(:original_exception) &&
813
(orig_exception = exception.original_exception) &&
@@ -12,10 +17,15 @@ def rescue_with_handler(exception)
1217
super(exception)
1318
end
1419

20+
def show_detailed_exceptions?
21+
consider_all_requests_local || request.local?
22+
end
23+
1524
private
1625
def process_action(*args)
1726
super
1827
rescue Exception => exception
28+
request.env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions?
1929
rescue_with_handler(exception) || raise(exception)
2030
end
2131
end

actionpack/lib/action_controller/railtie.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class Railtie < Rails::Railtie
2121
paths = app.config.paths
2222
options = app.config.action_controller
2323

24+
options.consider_all_requests_local ||= app.config.consider_all_requests_local
25+
2426
options.assets_dir ||= paths["public"].first
2527
options.javascripts_dir ||= paths["public/javascripts"].first
2628
options.stylesheets_dir ||= paths["public/stylesheets"].first

actionpack/test/controller/show_exceptions_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'abstract_unit'
22

33
module ShowExceptions
4-
class ShowExceptionsController < ActionController::Metal
4+
class ShowExceptionsController < ActionController::Base
55
use ActionDispatch::ShowExceptions
66

77
def boom
@@ -27,7 +27,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest
2727
end
2828

2929
test 'show diagnostics from a remote ip when consider_all_requests_local is true' do
30-
Rails.stubs(:application).returns stub(:config => stub(:consider_all_requests_local => true))
30+
ShowExceptionsController.any_instance.stubs(:consider_all_requests_local).returns(true)
3131
@app = ShowExceptionsController.action(:boom)
3232
self.remote_addr = '208.77.188.166'
3333
get '/'

0 commit comments

Comments
 (0)