Class: ActionDispatch::Rescue

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/middleware/rescue.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, rescuers = {}, &block) ⇒ Rescue

Returns a new instance of Rescue.



3
4
5
6
7
# File 'actionpack/lib/action_dispatch/middleware/rescue.rb', line 3

def initialize(app, rescuers = {}, &block)
  @app, @rescuers = app, {}
  rescuers.each { |exception, rescuer| rescue_from(exception, rescuer) }
  instance_eval(&block) if block_given?
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'actionpack/lib/action_dispatch/middleware/rescue.rb', line 9

def call(env)
  @app.call(env)
rescue Exception => exception
  if rescuer = @rescuers[exception.class.name]
    env['action_dispatch.rescue.exception'] = exception
    rescuer.call(env)
  else
    raise exception
  end
end