Commit 33abb5b80251548c9dbefb3edaef2efaa31abfb1
1 parent
1e637035
Exists in
master
and in
1 other branch
airbrake API 2.3 support
Showing
6 changed files
with
25 additions
and
6 deletions
Show diff stats
app/models/error_report.rb
| @@ -2,7 +2,7 @@ require 'digest/md5' | @@ -2,7 +2,7 @@ require 'digest/md5' | ||
| 2 | require 'hoptoad_notifier' | 2 | require 'hoptoad_notifier' |
| 3 | 3 | ||
| 4 | class ErrorReport | 4 | class ErrorReport |
| 5 | - attr_reader :error_class, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_attributes | 5 | + attr_reader :error_class, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_attributes, :current_user |
| 6 | 6 | ||
| 7 | def initialize(xml_or_attributes) | 7 | def initialize(xml_or_attributes) |
| 8 | @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access | 8 | @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access |
| @@ -41,7 +41,9 @@ class ErrorReport | @@ -41,7 +41,9 @@ class ErrorReport | ||
| 41 | :request => request, | 41 | :request => request, |
| 42 | :server_environment => server_environment, | 42 | :server_environment => server_environment, |
| 43 | :notifier => notifier, | 43 | :notifier => notifier, |
| 44 | - :user_attributes => user_attributes) | 44 | + :user_attributes => user_attributes, |
| 45 | + :current_user => current_user | ||
| 46 | + ) | ||
| 45 | 47 | ||
| 46 | err = app.find_or_create_err!( | 48 | err = app.find_or_create_err!( |
| 47 | :error_class => error_class, | 49 | :error_class => error_class, |
app/models/notice.rb
| @@ -11,6 +11,7 @@ class Notice | @@ -11,6 +11,7 @@ class Notice | ||
| 11 | field :request, :type => Hash | 11 | field :request, :type => Hash |
| 12 | field :notifier, :type => Hash | 12 | field :notifier, :type => Hash |
| 13 | field :user_attributes, :type => Hash | 13 | field :user_attributes, :type => Hash |
| 14 | + field :current_user, :type => Hash | ||
| 14 | field :error_class | 15 | field :error_class |
| 15 | 16 | ||
| 16 | belongs_to :err | 17 | belongs_to :err |
lib/hoptoad.rb
| @@ -3,7 +3,7 @@ require 'hoptoad/v2' | @@ -3,7 +3,7 @@ require 'hoptoad/v2' | ||
| 3 | module Hoptoad | 3 | module Hoptoad |
| 4 | class ApiVersionError < StandardError | 4 | class ApiVersionError < StandardError |
| 5 | def initialize | 5 | def initialize |
| 6 | - super "Wrong API Version: Expecting 2.0, 2.1, or 2.2" | 6 | + super "Wrong API Version: Expecting 2.0, 2.1, 2.2 or 2.3" |
| 7 | end | 7 | end |
| 8 | end | 8 | end |
| 9 | 9 | ||
| @@ -16,7 +16,7 @@ module Hoptoad | @@ -16,7 +16,7 @@ module Hoptoad | ||
| 16 | private | 16 | private |
| 17 | def self.get_version_processor(version) | 17 | def self.get_version_processor(version) |
| 18 | case version | 18 | case version |
| 19 | - when /2\.[012]/; Hoptoad::V2 | 19 | + when /2\.[0123]/; Hoptoad::V2 |
| 20 | else; raise ApiVersionError | 20 | else; raise ApiVersionError |
| 21 | end | 21 | end |
| 22 | end | 22 | end |
lib/hoptoad/v2.rb
| @@ -59,7 +59,8 @@ module Hoptoad | @@ -59,7 +59,8 @@ module Hoptoad | ||
| 59 | 59 | ||
| 60 | :api_key => notice['api-key'], | 60 | :api_key => notice['api-key'], |
| 61 | :notifier => notice['notifier'], | 61 | :notifier => notice['notifier'], |
| 62 | - :user_attributes => notice['user-attributes'] || {} | 62 | + :user_attributes => notice['user-attributes'] || {}, |
| 63 | + :current_user => notice['current-user'] || {} | ||
| 63 | } | 64 | } |
| 64 | end | 65 | end |
| 65 | end | 66 | end |
spec/fixtures/hoptoad_test_notice.xml
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | -<notice version="2.0"> | 2 | +<notice version="2.3"> |
| 3 | <api-key>APIKEY</api-key> | 3 | <api-key>APIKEY</api-key> |
| 4 | <notifier> | 4 | <notifier> |
| 5 | <name>Hoptoad Notifier</name> | 5 | <name>Hoptoad Notifier</name> |
| @@ -144,4 +144,10 @@ | @@ -144,4 +144,10 @@ | ||
| 144 | <project-root>/path/to/sample/project</project-root> | 144 | <project-root>/path/to/sample/project</project-root> |
| 145 | <environment-name>development</environment-name> | 145 | <environment-name>development</environment-name> |
| 146 | </server-environment> | 146 | </server-environment> |
| 147 | + <current-user> | ||
| 148 | + <id>123</id> | ||
| 149 | + <name>Mr. Bean</name> | ||
| 150 | + <email>mr.bean@example.com</email> | ||
| 151 | + <username>mrbean</username> | ||
| 152 | + </current-user> | ||
| 147 | </notice> | 153 | </notice> |
spec/models/app_spec.rb
| @@ -230,6 +230,15 @@ describe App do | @@ -230,6 +230,15 @@ describe App do | ||
| 230 | lambda { @notice = App.report_error!(xml) }.should_not raise_error | 230 | lambda { @notice = App.report_error!(xml) }.should_not raise_error |
| 231 | @notice.backtrace.length.should == 1 | 231 | @notice.backtrace.length.should == 1 |
| 232 | end | 232 | end |
| 233 | + | ||
| 234 | + it 'captures the current_user' do | ||
| 235 | + @notice = App.report_error!(@xml) | ||
| 236 | + @notice.current_user['id'].should == '123' | ||
| 237 | + @notice.current_user['name'].should == 'Mr. Bean' | ||
| 238 | + @notice.current_user['email'].should == 'mr.bean@example.com' | ||
| 239 | + @notice.current_user['username'].should == 'mrbean' | ||
| 240 | + end | ||
| 241 | + | ||
| 233 | end | 242 | end |
| 234 | 243 | ||
| 235 | 244 |