Class: Rack::RouteExceptions
Constant Summary collapse
- ROUTES =
[]
- ROUTE_EXCEPTIONS_PATH_INFO =
'rack.route_exceptions.path_info'.freeze
- ROUTE_EXCEPTIONS_EXCEPTION =
'rack.route_exceptions.exception'.freeze
- ROUTE_EXCEPTIONS_RETURNED =
'rack.route_exceptions.returned'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call(env, try_again = true) ⇒ Object
-
#initialize(app) ⇒ RouteExceptions
constructor
A new instance of RouteExceptions.
- #route(to, env, returned, exception) ⇒ Object
Constructor Details
#initialize(app) ⇒ RouteExceptions
Returns a new instance of RouteExceptions.
18 19 20 |
# File 'lib/vendor/route_exceptions.rb', line 18 def initialize(app) @app = app end |
Class Method Details
Instance Method Details
#call(env, try_again = true) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vendor/route_exceptions.rb', line 22 def call(env, try_again = true) returned = @app.call(env) rescue Exception => exception raise(exception) unless try_again ROUTES.each do |klass, to| next unless klass === exception return route(to, env, returned, exception) end raise(exception) end |
#route(to, env, returned, exception) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vendor/route_exceptions.rb', line 35 def route(to, env, returned, exception) hash = { ROUTE_EXCEPTIONS_PATH_INFO => env['PATH_INFO'], ROUTE_EXCEPTIONS_EXCEPTION => exception, ROUTE_EXCEPTIONS_RETURNED => returned } env.merge!(hash) env['PATH_INFO'] = to call(env, try_again = false) end |