lib/wat_catcher/middleware.rb in wat_catcher-0.0.8 vs lib/wat_catcher/middleware.rb in wat_catcher-0.1.0

- old
+ new

@@ -1,36 +1,38 @@ 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 + request = env["action_controller.instance"].request + params = request.filtered_parameters + 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 + # 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 + ::WatCatcher::SidekiqPoster.perform_async( + "#{WatCatcher.configuration.host}/wats", + { + wat: { + page_url: page_url, + request_params: params, + session: session, + backtrace: excpt.backtrace.to_a, + message: excpt.message, + error_class: excpt.class.to_s + } + }) raise end end + + end \ No newline at end of file