Sha256: 46cbe8118589da8c13633cc5124ac2e6502135ff60862af1edc0c46ef2bd9327

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

module WatCatcher
  class Middleware
    def initialize(app)
      @app = app
      @client = HTTPClient.new
      @backgrounder = ::WatCatcher::Backgrounder.new
    end

    def call(env)
      @app.call(env)
    rescue
      excpt = $!
      @backgrounder.queue do
        request = ::Rack::Request.new(env)
        params = request.params
        session = request.session.as_json
        page_url = request.url

        # Build the clean url (hide the port if it is obvious)
        url = "#{request.scheme}://#{request.host}"
        url << ":#{request.port}" unless [80, 443].include?(request.port)
        url << request.fullpath

        @client.post("#{WatCatcher.configuration.host}/wats",
                       "wat[page_url]" => page_url,
                       "wat[request_params]" => params,
                       "wat[session]" => session,
                       "wat[backtrace][]" => excpt.backtrace.to_a,
                       "wat[message]" => excpt.message,
                       "wat[error_class]" => excpt.class.to_s
                    )
      end
      raise
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
wat_catcher-0.0.8 lib/wat_catcher/middleware.rb
wat_catcher-0.0.7 lib/wat_catcher/middleware.rb
wat_catcher-0.0.6 lib/wat_catcher/middleware.rb
wat_catcher-0.0.5 lib/wat_catcher/middleware.rb
wat_catcher-0.0.4 lib/wat_catcher/middleware.rb
wat_catcher-0.0.3 lib/wat_catcher/middleware.rb
wat_catcher-0.0.2 lib/wat_catcher/middleware.rb