Class: Trouble::Middleware
- Inherits:
-
Object
- Object
- Trouble::Middleware
- Defined in:
- lib/trouble/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
4 5 6 |
# File 'lib/trouble/middleware.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/trouble/middleware.rb', line 8 def call(env) # calling env.dup here prevents bad things from happening request = Rack::Request.new(env.dup) # calling request.params is sufficient to trigger the "invalid %-encoding" error # see https://github.com/rack/rack/issues/337#issuecomment-46453404 request.params @app.call(env) rescue ArgumentError => exception raise unless exception..include?('invalid %-encoding') return [400, {}, ['']] rescue => exception logger.fatal [$!.class, $!., $!.backtrace[2..5]].join("\n") ::Trouble.notify exception raise end |