Commit d3608428d9339777134ecd8084ca62bd698bd1e7
1 parent
c2962c8e
Exists in
master
and in
1 other branch
Fix parsing V3 api notice without backtrace
Fixes #828.
Showing
3 changed files
with
42 additions
and
1 deletions
Show diff stats
lib/airbrake_api/v3/notice_parser.rb
| @@ -32,7 +32,7 @@ module AirbrakeApi | @@ -32,7 +32,7 @@ module AirbrakeApi | ||
| 32 | end | 32 | end |
| 33 | 33 | ||
| 34 | def backtrace | 34 | def backtrace |
| 35 | - error['backtrace'].map do |backtrace_line| | 35 | + (error['backtrace'] || []).map do |backtrace_line| |
| 36 | { | 36 | { |
| 37 | method: backtrace_line['function'], | 37 | method: backtrace_line['function'], |
| 38 | file: backtrace_line['file'], | 38 | file: backtrace_line['file'], |
| @@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
| 1 | +{ | ||
| 2 | + "notifier":{"name":"airbrake-js-v8","version":"0.3.10","url":"https://github.com/airbrake/airbrake-js"}, | ||
| 3 | + "errors":[ | ||
| 4 | + { | ||
| 5 | + "type":"Error", | ||
| 6 | + "message":"Error: TestError", | ||
| 7 | + "backtrace":null | ||
| 8 | + } | ||
| 9 | + ], | ||
| 10 | + "context":{ | ||
| 11 | + "language":"JavaScript", | ||
| 12 | + "sourceMapEnabled":true, | ||
| 13 | + "userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36", | ||
| 14 | + "url":"http://localhost:3000/kontakt", | ||
| 15 | + "userId":1,"userUsername":"john", | ||
| 16 | + "userName":"John Doe", | ||
| 17 | + "userUsername": "john", | ||
| 18 | + "userEmail":"john.doe@example.org", | ||
| 19 | + "version":"1.0", | ||
| 20 | + "component":"ContactsController", | ||
| 21 | + "action":"show" | ||
| 22 | + }, | ||
| 23 | + "params":{"returnTo":"dashboard"}, | ||
| 24 | + "environment":{"navigator_vendor":"Google Inc."}, | ||
| 25 | + "session":{"isAdmin":true}, | ||
| 26 | + "key":"a3969bfbf65f073921e", | ||
| 27 | + "project_id":"a3969bfbf65f073921e" | ||
| 28 | +} | ||
| 0 | \ No newline at end of file | 29 | \ No newline at end of file |
spec/lib/airbrake_api/v3/notice_parser_spec.rb
| @@ -36,6 +36,19 @@ describe AirbrakeApi::V3::NoticeParser do | @@ -36,6 +36,19 @@ describe AirbrakeApi::V3::NoticeParser do | ||
| 36 | expect(report).to be_valid | 36 | expect(report).to be_valid |
| 37 | end | 37 | end |
| 38 | 38 | ||
| 39 | + it 'parses JSON payload with missing backtrace' do | ||
| 40 | + json = Rails.root.join('spec', 'fixtures', 'api_v3_request_without_backtrace.json').read | ||
| 41 | + params = JSON.parse(json) | ||
| 42 | + params['key'] = app.api_key | ||
| 43 | + | ||
| 44 | + report = AirbrakeApi::V3::NoticeParser.new(params).report | ||
| 45 | + notice = report.generate_notice! | ||
| 46 | + | ||
| 47 | + expect(report.error_class).to eq('Error') | ||
| 48 | + expect(report.message).to eq('Error: TestError') | ||
| 49 | + expect(report.backtrace.lines.size).to eq(0) | ||
| 50 | + end | ||
| 51 | + | ||
| 39 | def build_params(options = {}) | 52 | def build_params(options = {}) |
| 40 | json = Rails.root.join('spec', 'fixtures', 'api_v3_request.json').read | 53 | json = Rails.root.join('spec', 'fixtures', 'api_v3_request.json').read |
| 41 | data = JSON.parse(json) | 54 | data = JSON.parse(json) |