Class: KaeruEra::Reporter
- Inherits:
-
Object
- Object
- KaeruEra::Reporter
- Defined in:
- lib/kaeruera/reporter.rb
Overview
The standard Reporter class reports errors via HTTP requests to a KaeruEra web server.
Instance Method Summary collapse
-
#initialize(url, application_id, token) ⇒ Reporter
constructor
- Arguments: url
-
The url to use to report the error.
-
#report(opts = {}) ⇒ Object
If an error cannot be determined, returns false.
Constructor Details
#initialize(url, application_id, token) ⇒ Reporter
Arguments:
- url
-
The url to use to report the error.
- application_id
-
The id for the application on the KaeruEra server.
- token
-
The application’s token on the KaeruEra server.
You can get this information from looking at the “Reporter Info” page on the KaeruEra server.
16 17 18 19 20 |
# File 'lib/kaeruera/reporter.rb', line 16 def initialize(url, application_id, token) @url = url @application_id = application_id @token = token end |
Instance Method Details
#report(opts = {}) ⇒ Object
If an error cannot be determined, returns false. Otherwise, reports the error to the KaeruEra server via HTTP. If an exception would be raised by this code, returns the exception instead of raising it.
Options:
- :error
-
The exception to report
- :env
-
The environment variables related to this exception. For a web application, generally the HTTP request environment variables.
- :params
-
The params related to the exception. For a web application, generally the GET/POST parameters.
- :session
-
Any session information to the exception.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/kaeruera/reporter.rb', line 35 def report(opts={}) return false unless error = opts[:error] || $! h = { :error_class=>error.class.name, :message=>error..to_s, :backtrace=>error.backtrace } if v = opts[:params] h[:params] = v end if v = opts[:session] h[:session] = v end if v = opts[:env] h[:env] = v end url = URI.parse(@url) req = Net::HTTP::Post.new(url.path) req.body = {:data=>h, :id=>@application_id, :token=>@token}.to_json req['Content-Type'] = 'application/json' req['Accept'] = 'application/json' req.basic_auth(url.user, url.password) if url.user http = Net::HTTP.new(url.host, url.port) http.use_ssl = true if url.scheme == 'https' res = http.start do http.request(req) end JSON.parse(res.body)['error_id'] rescue => e e end |