Sha256: a12da9eb6f5647ede417d3edb37a3ed0b1c7f423b22d9c8b4526afa3561cc125

Contents?: true

Size: 1.43 KB

Versions: 18

Compression:

Stored size: 1.43 KB

Contents

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.io/terms.html

require 'json'
require 'sqreen/event'

module Sqreen
  # When an exception arise it is automatically pushed to the event queue
  class RemoteException < Sqreen::Event
    def self.record(payload_or_exception)
      exception = RemoteException.new(payload_or_exception)
      exception.enqueue
    end

    def initialize(payload_or_exception)
      payload = if payload_or_exception.is_a?(Hash)
                  payload_or_exception
                else
                  { 'exception' => payload_or_exception }
                end
      super(payload)
    end

    def enqueue
      Sqreen.queue.push(self)
    end

    def klass
      payload['exception'].class.name
    end

    def to_hash
      exception = payload['exception']
      ev = {
        :klass => exception.class.name,
        :message => exception.message,
        :params => payload['request_params'],
        :time => payload['time'],
        :infos => {
          :client_ip => payload['client_ip'],
        },
        :request => payload['request_infos'],
        :rule_name => payload['rule_name'],
        :rulespack_id => payload['rulespack_id'],
      }

      ev[:infos].merge!(payload['infos']) if payload['infos']
      return ev unless exception.backtrace
      ev[:context] = { :backtrace => exception.backtrace.map(&:to_s) }
      ev
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
sqreen-1.1.01481108064-java lib/sqreen/events/remote_exception.rb
sqreen-1.1.01481108064 lib/sqreen/events/remote_exception.rb
sqreen-1.1.0.pre1481104810 lib/sqreen/events/remote_exception.rb
sqreen-1.0.0.pre1480953244 lib/sqreen/events/remote_exception.rb
sqreen-0.8.11465220943-java lib/sqreen/events/remote_exception.rb
sqreen-0.8.11465220943 lib/sqreen/events/remote_exception.rb
sqreen-0.8.01464630418-java lib/sqreen/events/remote_exception.rb
sqreen-0.8.01464630418 lib/sqreen/events/remote_exception.rb
sqreen-0.7.01464629603-java lib/sqreen/events/remote_exception.rb
sqreen-0.7.01464629603 lib/sqreen/events/remote_exception.rb
sqreen-0.7.01462198090-java lib/sqreen/events/remote_exception.rb
sqreen-0.7.01462198090 lib/sqreen/events/remote_exception.rb
sqreen-0.7.01461829538-java lib/sqreen/events/remote_exception.rb
sqreen-0.7.01461829538 lib/sqreen/events/remote_exception.rb
sqreen-0.7.01461767359-java lib/sqreen/events/remote_exception.rb
sqreen-0.7.01461767359 lib/sqreen/events/remote_exception.rb
sqreen-0.7.01461158029-java lib/sqreen/events/remote_exception.rb
sqreen-0.7.01461158029 lib/sqreen/events/remote_exception.rb