Class: CrashHook::Crash

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/crash_hook/crash.rb

Constant Summary

Constants included from Request

Request::CONTENT_TYPES, Request::OPEN_TIMEOUT, Request::TIMEOUT

Instance Method Summary collapse

Methods included from Request

#delete, #get, #post, #put

Constructor Details

#initialize(config, exception = nil, env = {}) ⇒ Crash

Initialize a new Crash object

config    => CrashHook::Configuration object
exception => Exception raised from middleware
env       => Environment variable

Raises:

  • (ArgumentError)

12
13
14
15
16
17
18
19
20
21
22
# File 'lib/crash_hook/crash.rb', line 12

def initialize(config, exception=nil, env={})
  unless config.kind_of?(CrashHook::Configuration)
    raise ArgumentError, "CrashHook::Configuration required!"
  end
  
  raise ArgumentError, "Exception required!" if exception.nil?
  raise ArgumentError, "Environment required!" if env.nil?
  
  @config = config
  @payload = CrashHook::Payload.new(exception, env, @config.extra_params)
end

Instance Method Details

#notifyObject

Send notification to the endpoint


25
26
27
28
29
30
31
32
33
# File 'lib/crash_hook/crash.rb', line 25

def notify
  begin
    request(@config.method, @config.url, payload_data, @config.format)
    true
  rescue Exception => ex
    log_error(ex) if @config.has_logger?
    false
  end
end