Class: DaemonKit::ErrorHandlers::Hoptoad
- Defined in:
- lib/daemon_kit/error_handlers/hoptoad.rb
Overview
Error reporting via Hoptoad.
Defined Under Namespace
Classes: Backtrace
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
Methods inherited from Base
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
115 116 117 |
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 115 def api_key @api_key end |
Instance Method Details
#format_exception(exception) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 145 def format_exception( exception ) lines = Backtrace.parse( exception.backtrace ) = exception. .gsub!("\"",""") .gsub!("'","'") .gsub!("&","&") .gsub!("<","<") .gsub!(">",">") <<-EOF <?xml version="1.0" encoding="UTF-8"?> <notice version="2.0"> <api-key>#{self.api_key}</api-key> <notifier> <name>daemon-kit</name> <version>#{DaemonKit::VERSION}</version> <url>http://github.com/kennethkalmer/daemon-kit</url> </notifier> <error> <class>#{exception.class.name}</class> <message>#{}</message> <backtrace> #{Backtrace.parse( exception.backtrace ).lines.inject('') { |string,line| string << line.to_xml }} </backtrace> </error> <server-environment> <project-root>#{DaemonKit.root}</project-root> <environment-name>#{DaemonKit.env}</environment-name> </server-environment> </notice> EOF end |
#handle_exception(exception) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 117 def handle_exception( exception ) headers = { 'Content-type' => 'text/xml', 'Accept' => 'text/xml, application/xml' } http = Net::HTTP.new( url.host, url.port ) data = format_exception( exception ) DaemonKit.logger.debug("Sending to Hoptoad: #{data}") response = begin http.post( url.path, data, headers ) rescue TimeoutError => 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 |
#url ⇒ Object
141 142 143 |
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 141 def url URI.parse("http://hoptoadapp.com/notifier_api/v2/notices") end |