Class: ErrorappNotifier::FailureData

Inherits:
Object
  • Object
show all
Defined in:
lib/errorapp_notifier/failure_data.rb

Direct Known Subclasses

ControllerFailureData, RackFailureData

Instance Method Summary collapse

Constructor Details

#initialize(exception, name = nil) ⇒ FailureData

Returns a new instance of FailureData.



8
9
10
11
# File 'lib/errorapp_notifier/failure_data.rb', line 8

def initialize(exception, name = nil)
  @exception = exception
  @name = name
end

Instance Method Details

#to_hashObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/errorapp_notifier/failure_data.rb', line 13

def to_hash
  hash = {}
  hash.merge!(ExceptionData.new(@exception).data)
  hash.merge!(ApplicationEnvironmentData.new(@exception).data)
  hash.merge!(extra_stuff)
  hash.merge!(context_stuff)
  hash.merge!(errorapp_client_data)
  rescue_sanitize_hash do
    Sanitizer.sanitize_hash(hash)
  end
end

#to_jsonObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/errorapp_notifier/failure_data.rb', line 25

def to_json
  begin
    to_hash.to_json
  rescue NoMethodError
    begin
      require 'json'
      return to_hash.to_json
    rescue StandardError => e
      ErrorappNotifier.logger.error(e.message)
      ErrorappNotifier.logger.error(e.backtrace)
      raise StandardError.new("You need a json gem/library installed to send errors to ErrorApp (Object.to_json not defined). \nInstall json_pure, yajl-ruby, json-jruby, or the c-based json gem")
    end
  end
end

#uniq_keyObject



40
41
42
43
# File 'lib/errorapp_notifier/failure_data.rb', line 40

def uniq_key
  return nil if (@exception.backtrace.nil? || @exception.backtrace.empty?)
  Digest::MD5.hexdigest(@exception.backtrace.join)
end