diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-09-15 16:33:15 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-09-15 16:33:15 -0500 |
commit | 52aeb8d2e72223f9b40b0193c151c252a3f4fb09 (patch) | |
tree | 96ac7e1b9f0beafbc0dc51cea4070789d3b9980f /actionpack/lib/action_dispatch/middleware/rescue.rb | |
parent | 90d7ae23c6f5a7e914d8b9fd74481ac61b6c4fb9 (diff) | |
download | rails-52aeb8d2e72223f9b40b0193c151c252a3f4fb09.tar.gz rails-52aeb8d2e72223f9b40b0193c151c252a3f4fb09.tar.bz2 rails-52aeb8d2e72223f9b40b0193c151c252a3f4fb09.zip |
Beef up AD::Rescue to replace global exception handling lost in ApplicationController
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/rescue.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/rescue.rb | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/rescue.rb b/actionpack/lib/action_dispatch/middleware/rescue.rb index 1456825526..aee672112c 100644 --- a/actionpack/lib/action_dispatch/middleware/rescue.rb +++ b/actionpack/lib/action_dispatch/middleware/rescue.rb @@ -1,14 +1,26 @@ module ActionDispatch class Rescue - def initialize(app, rescuer) - @app, @rescuer = app, rescuer + def initialize(app, rescuers = {}, &block) + @app, @rescuers = app, {} + rescuers.each { |exception, rescuer| rescue_from(exception, rescuer) } + instance_eval(&block) if block_given? end def call(env) @app.call(env) rescue Exception => exception - env['action_dispatch.rescue.exception'] = exception - @rescuer.call(env) + if rescuer = @rescuers[exception.class.name] + env['action_dispatch.rescue.exception'] = exception + rescuer.call(env) + else + raise exception + end end + + protected + def rescue_from(exception, rescuer) + exception = exception.class.name if exception.is_a?(Exception) + @rescuers[exception.to_s] = rescuer + end end end |