class Rack::RouteExceptions

Constants

EXCEPTION
PATH_INFO
RETURNED
ROUTES

Public Class Methods

[]=(exception, to)
Alias for: route
new(app) click to toggle source
   # File lib/rack/contrib/route_exceptions.rb
22 def initialize(app)
23   @app = app
24 end
route(exception, to) click to toggle source
   # File lib/rack/contrib/route_exceptions.rb
14 def route(exception, to)
15   ROUTES.delete_if{|k,v| k == exception }
16   ROUTES << [exception, to]
17 end
Also aliased as: []=

Public Instance Methods

call(env, try_again = true) click to toggle source
   # File lib/rack/contrib/route_exceptions.rb
26 def call(env, try_again = true)
27   returned = @app.call(env)
28 rescue Exception => exception
29   raise(exception) unless try_again
30 
31   ROUTES.each do |klass, to|
32     next unless klass === exception
33     return route(to, env, returned, exception)
34   end
35 
36   raise(exception)
37 end
route(to, env, returned, exception) click to toggle source
   # File lib/rack/contrib/route_exceptions.rb
39 def route(to, env, returned, exception)
40   env.merge!(
41     PATH_INFO => env['PATH_INFO'],
42     EXCEPTION => exception,
43     RETURNED => returned
44   )
45 
46   env['PATH_INFO'] = to
47 
48   call(env, try_again = false)
49 end