Sha256: 222c990b682c37656f5dac318747a060c8174d6f1f3229841d4ed5ffb4cf310f

Contents?: true

Size: 1.45 KB

Versions: 27

Compression:

Stored size: 1.45 KB

Contents

module Logster
  module Middleware
    class Reporter

      PATH_INFO = "PATH_INFO".freeze
      SCRIPT_NAME = "SCRIPT_NAME".freeze

      def initialize(app, config={})
        @app = app
        @error_path = Logster.config.subdirectory + '/report_js_error'
      end

      def call(env)
        Thread.current[Logster::Logger::LOGSTER_ENV] = env


        path = env[PATH_INFO]
        script_name = env[SCRIPT_NAME]

        if script_name && script_name.length > 0
          path = script_name + path
        end

        if path == @error_path
          Logster.config.current_context.call(env) do
            report_js_error(env)
          end
          return [200,{},["OK"]]
        end

        @app.call(env)
      ensure
        Thread.current[Logster::Logger::LOGSTER_ENV] = nil
      end

      def report_js_error(env)
        req = Rack::Request.new(env)
        message = req["message"] || ""
        message << "\nUrl: " << req["url"] if req["url"]
        message << "\nLine: " << req["line"] if req["line"]
        message << "\nColumn: " << req["column"] if req["column"]
        message << "\nWindow Location: " << req["window_location"] if req["window_location"]

        backtrace = req["stacktrace"] || ""
        Logster.store.report(::Logger::Severity::WARN,
                            "javascript",
                            message,
                            backtrace: backtrace,
                            env: env)
      end

    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
logster-1.2.11 lib/logster/middleware/reporter.rb
logster-1.2.9 lib/logster/middleware/reporter.rb
logster-1.2.8 lib/logster/middleware/reporter.rb
logster-1.2.7 lib/logster/middleware/reporter.rb
logster-1.2.6 lib/logster/middleware/reporter.rb
logster-1.2.5 lib/logster/middleware/reporter.rb
logster-1.2.4 lib/logster/middleware/reporter.rb
logster-1.2.3 lib/logster/middleware/reporter.rb
logster-1.2.2 lib/logster/middleware/reporter.rb
logster-1.2.1 lib/logster/middleware/reporter.rb
logster-1.2.0 lib/logster/middleware/reporter.rb
logster-1.1.1 lib/logster/middleware/reporter.rb
logster-1.0.1 lib/logster/middleware/reporter.rb
logster-1.0.0.3.pre lib/logster/middleware/reporter.rb
logster-1.0.0.2.pre lib/logster/middleware/reporter.rb
logster-1.0.0.1.pre lib/logster/middleware/reporter.rb
logster-1.0.0.0.pre lib/logster/middleware/reporter.rb
logster-0.9.9 lib/logster/middleware/reporter.rb
logster-0.8.4.8.pre lib/logster/middleware/reporter.rb
logster-0.8.4.7.pre lib/logster/middleware/reporter.rb