Class: Exceptiontrap::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/exceptiontrap/notifier.rb

Class Method Summary collapse

Class Method Details

.notify(data) ⇒ Object



4
5
6
7
8
# File 'lib/exceptiontrap/notifier.rb', line 4

def notify(data)
  @data = data
  serialized_data = { :problem => data }.to_json
  send_problem(serialized_data) unless ignore_exception?
end

.send_problem(serialized_data) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/exceptiontrap/notifier.rb', line 10

def send_problem(serialized_data)
  url = URI.parse((Config.use_ssl? ? 'https://' : 'http://') << Config.notification_url)
  client = prepare_client(url)

  headers = HEADERS
  headers['X-Api-Key'] = Config.api_key

  response = begin
    client.post(url.path, serialized_data, headers)
  rescue TimeoutError => e
    puts 'ERROR: Timeout while contacting Exceptiontrap.'
    nil
  rescue Exception => e
    puts "ERROR: Error on sending: #{e.class} - #{e.message}"
  end
end