Class: Squash::Padrino::Rack
- Inherits:
-
Object
- Object
- Squash::Padrino::Rack
- Defined in:
- lib/squash/padrino/rack.rb
Overview
Rack middleware that catches exceptions thrown outside the scope of Padrino’s request processing.
Instance Method Summary collapse
-
#call(env) ⇒ Hash
Rescues any exceptions thrown downstream, notifies Squash, then re-raises them.
-
#filter_for_squash(data, kind) ⇒ Object
abstract
Override this method to implement filtering of sensitive data in the headers, cookies, and rack hashes (see #squash_rack_data).
-
#initialize(app) ⇒ Rack
constructor
Instantiates the middleware.
-
#squash_rack_data(env) ⇒ Hash<Symbol, Object>
The additional information this middleware gives to ‘Squash::Ruby.notify`.
Constructor Details
#initialize(app) ⇒ Rack
Instantiates the middleware.
27 28 29 |
# File 'lib/squash/padrino/rack.rb', line 27 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Hash
Rescues any exceptions thrown downstream, notifies Squash, then re-raises them.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/squash/padrino/rack.rb', line 36 def call(env) begin result = @app.call(env) rescue ::Exception => ex env['squash.notified'] = ::Squash::Ruby.notify(ex, squash_rack_data(env)) raise ex end result end |
#filter_for_squash(data, kind) ⇒ Object
Override this method to implement filtering of sensitive data in the headers, cookies, and rack hashes (see #squash_rack_data). The method signature is the same as ‘Squash::Ruby#filter_for_squash`, but `kind` can also be `:env` for the Rack environment hash.
54 55 56 |
# File 'lib/squash/padrino/rack.rb', line 54 def filter_for_squash(data, kind) data end |
#squash_rack_data(env) ⇒ Hash<Symbol, Object>
Returns The additional information this middleware gives to ‘Squash::Ruby.notify`.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/squash/padrino/rack.rb', line 60 def squash_rack_data(env) data = { :headers => filter_for_squash(request_headers(env), :headers), :request_method => env['REQUEST_METHOD'].to_s.upcase, :schema => env['rack.url_scheme'], :host => env['SERVER_NAME'], :port => env['SERVER_PORT'], :path => env['PATH_INFO'], :query => env['QUERY_STRING'], :params => filter_for_squash(env['rack.request.query_hash'], :params), :body => filter_for_squash(env['rack.input'].read, :body), :session => filter_for_squash(env['rack.session'], :session), :cookies => filter_for_squash(env['rack.request.cookie_hash'], :cookies), :"rack.env" => filter_for_squash(env, :rack) } env['rack.input'].rewind data end |