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.
15 16 17 18 19 |
# File 'lib/kaeruera/reporter.rb', line 15 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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kaeruera/reporter.rb', line 34 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 res = RestClient.post @url, {:data=>h, :id=>@application_id, :token=>@token}.to_json, :content_type => :json, :accept => :json JSON.parse(res)['error_id'] rescue => e e end |