Sha256: 718ae484c53c4cacb9d58fc67384e0d3db155afd8b79c4947386a4436cf385ac

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

require 'mongo'

module YogiBerra
  class Data
    def self.store!(exception, environment = nil)
      data = parse_exception(exception)
      if environment
        session = environment.delete(:session)
        data[:session] = parse_session(session) if session
        data.merge!(environment)
      end
      YogiBerra::Catcher.connection["caught_exceptions"].insert(data)
    end

    def self.parse_exception(notice)
      data_hash = {
        :error_class => "#{notice.exception.class}",
        :project => YogiBerra::Catcher.settings["project"],
        :error_message => notice.respond_to?(:error_message) ? notice.error_message : notice.message
      }
      data_hash[:backtraces] = notice.backtrace
      if notice.backtrace.respond_to?(:lines) && notice.backtrace.lines.any?
        data_hash[:backtraces] = notice.backtrace.lines.collect(&:to_s)
      end
      data_hash[:created_at] = Time.now.utc
      data_hash
    end

    def self.parse_session(session)
      session.inject({}) do |result, element|
        key = element.first
        value = element.last
        if value.respond_to?(:as_json)
          result[key] = value.as_json(:except => ["password"])
        else
          value.delete("password")
          result[key] = value
        end
        result
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yogi_berra-0.1.0 lib/yogi_berra/data.rb
yogi_berra-0.0.15 lib/yogi_berra/data.rb
yogi_berra-0.0.14 lib/yogi_berra/data.rb
yogi_berra-0.0.13 lib/yogi_berra/data.rb
yogi_berra-0.0.12 lib/yogi_berra/data.rb
yogi_berra-0.0.11 lib/yogi_berra/data.rb
yogi_berra-0.0.10 lib/yogi_berra/data.rb
yogi_berra-0.0.9 lib/yogi_berra/data.rb