Class: DaemonKit::ErrorHandlers::Hoptoad

Inherits:
Base show all
Defined in:
lib/daemon_kit/error_handlers/hoptoad.rb

Overview

Error reporting via Hoptoad.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, instance

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



10
11
12
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 10

def api_key
  @api_key
end

Instance Method Details

#clean_exception(exception) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 39

def clean_exception( exception )
  data = {
    :api_key       => self.api_key,
    :error_class   => exception.class.name,
    :error_message => "#{exception.class.name}: #{exception.message}",
    :backtrace     => exception.backtrace,
    :environment   => ENV.to_hash,
    :request       => [],
    :session       => []
  }

  stringify_keys( data )
end

#handle_exception(exception) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 12

def handle_exception( exception )
  headers = {
    'Content-type' => 'application/x-yaml',
    'Accept' => 'text/xml, application/xml'
  }

  http = Net::HTTP.new( url.host, url.port )
  data = clean_exception( exception )

  response = begin
               http.post( url.path, data.to_yaml, headers )
             rescue TimoutError => e
               DaemonKit.logger.error("Timeout while contacting the Hoptoad server.")
               nil
             end
  case response
  when Net::HTTPSuccess then
    DaemonKit.logger.info "Hoptoad Success: #{response.class}"
  else
    DaemonKit.logger.error "Hoptoad Failure: #{response.class}\n#{response.body if response.respond_to? :body}"
  end
end

#stringify_keys(hash) ⇒ Object

:nodoc:



53
54
55
56
57
58
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 53

def stringify_keys(hash) #:nodoc:
  hash.inject({}) do |h, pair|
    h[pair.first.to_s] = pair.last.is_a?(Hash) ? stringify_keys(pair.last) : pair.last
    h
  end
end

#urlObject



35
36
37
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 35

def url
  URI.parse("http://hoptoadapp.com/notices/")
end