diff --git a/README.md b/README.md index 6489683..b86e7c8 100644 --- a/README.md +++ b/README.md @@ -249,10 +249,6 @@ Airbrake.setProject("ERRBIT API KEY", "ERRBIT API KEY"); Airbrake.setHost("http://errbit.yourdomain.com"); ``` -NOTE: Errbit is known to work with airbrake-js v0.5.2. Newer versions of -will not work until we figure out how to deal with: -https://github.com/airbrake/airbrake-js/pull/174#issuecomment-164918928 - Plugins and Integrations ------------------------ You can extend Errbit by adding Ruby gems and plugins which are typically gems. diff --git a/lib/airbrake_api/v3/notice_parser.rb b/lib/airbrake_api/v3/notice_parser.rb index b4811a7..1cdb48c 100644 --- a/lib/airbrake_api/v3/notice_parser.rb +++ b/lib/airbrake_api/v3/notice_parser.rb @@ -9,18 +9,20 @@ module AirbrakeApi @params = params || {} end - def report - attributes = { + def attributes + { error_class: error['type'], message: error['message'], backtrace: backtrace, request: request, server_environment: server_environment, api_key: params['key'].present? ? params['key'] : params['project_id'], - notifier: params['notifier'], + notifier: context['notifier'] || params['notifier'], user_attributes: user_attributes } + end + def report ErrorReport.new(attributes) end diff --git a/spec/lib/airbrake_api/v3/notice_parser_spec.rb b/spec/lib/airbrake_api/v3/notice_parser_spec.rb index d434554..ad656ea 100644 --- a/spec/lib/airbrake_api/v3/notice_parser_spec.rb +++ b/spec/lib/airbrake_api/v3/notice_parser_spec.rb @@ -1,20 +1,27 @@ describe AirbrakeApi::V3::NoticeParser do let(:app) { Fabricate(:app) } + let(:notifier_params) do + { + 'name' => 'notifiername', + 'version' => 'notifierversion', + 'url' => 'notifierurl' + } + end it 'raises error when errors attribute is missing' do expect do - AirbrakeApi::V3::NoticeParser.new({}).report + described_class.new({}).report end.to raise_error(AirbrakeApi::ParamsError) expect do - AirbrakeApi::V3::NoticeParser.new('errors' => []).report + described_class.new('errors' => []).report end.to raise_error(AirbrakeApi::ParamsError) end it 'parses JSON payload and returns ErrorReport' do params = build_params(key: app.api_key) - report = AirbrakeApi::V3::NoticeParser.new(params).report + report = described_class.new(params).report notice = report.generate_notice! expect(report.error_class).to eq('Error') @@ -37,7 +44,7 @@ describe AirbrakeApi::V3::NoticeParser do it 'parses JSON payload when api_key is missing but project_id is present' do params = build_params(key: nil, project_id: app.api_key) - report = AirbrakeApi::V3::NoticeParser.new(params).report + report = described_class.new(params).report expect(report).to be_valid end @@ -46,7 +53,7 @@ describe AirbrakeApi::V3::NoticeParser do params = JSON.parse(json) params['key'] = app.api_key - report = AirbrakeApi::V3::NoticeParser.new(params).report + report = described_class.new(params).report report.generate_notice! expect(report.error_class).to eq('Error') @@ -54,6 +61,22 @@ describe AirbrakeApi::V3::NoticeParser do expect(report.backtrace.lines.size).to eq(0) end + it 'takes the notifier from root' do + parser = described_class.new( + 'errors' => ['MyError'], + 'notifier' => notifier_params, + 'environment' => {}) + expect(parser.attributes[:notifier]).to eq(notifier_params) + end + + it 'takes the notifier from the context' do + parser = described_class.new( + 'errors' => ['MyError'], + 'context' => { 'notifier' => notifier_params }, + 'environment' => {}) + expect(parser.attributes[:notifier]).to eq(notifier_params) + end + def build_params(options = {}) json = Rails.root.join('spec', 'fixtures', 'api_v3_request.json').read data = JSON.parse(json) -- libgit2 0.21.2