From f57ccf87f005c1e7dff5ae12ec61e12a472cd2b6 Mon Sep 17 00:00:00 2001 From: Hugo Correia Date: Wed, 31 Mar 2021 12:25:56 +0100 Subject: [PATCH 1/4] Change the sentry error_reporter strategy With the new release of sentry lib: https://docs.sentry.io/platforms/ruby/migration/ sentry-raven has been deprecated in favour of sentry-ruby. This MR changes the strategy used to start using the new Sentry lib instead of using Raven. --- lib/api_error_handler/error_reporter.rb | 7 ++++- lib/api_error_handler/version.rb | 2 +- spec/api_error_handler/error_reporter_spec.rb | 28 +++++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/api_error_handler/error_reporter.rb b/lib/api_error_handler/error_reporter.rb index d6de713..d99c14b 100644 --- a/lib/api_error_handler/error_reporter.rb +++ b/lib/api_error_handler/error_reporter.rb @@ -19,11 +19,16 @@ def report(error, error_id: nil) context = error_id ? { error_id: error_id } : {} Honeybadger.notify(error, context: context) - elsif @strategy == :raven || @strategy == :sentry + elsif @strategy == :raven raise_dependency_error(missing_constant: "Raven") unless defined?(Raven) extra = error_id ? { error_id: error_id } : {} Raven.capture_exception(error, extra: extra) + elsif @strategy == :sentry + raise_dependency_error(missing_constant: "Sentry") unless defined?(Sentry) + + extra = error_id ? { error_id: error_id } : {} + Sentry.capture_exception(error, extra: extra) else raise( InvalidOptionError, diff --git a/lib/api_error_handler/version.rb b/lib/api_error_handler/version.rb index 0ca41f3..364e34c 100644 --- a/lib/api_error_handler/version.rb +++ b/lib/api_error_handler/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ApiErrorHandler - VERSION = "0.2.0" + VERSION = "0.3.0" end diff --git a/spec/api_error_handler/error_reporter_spec.rb b/spec/api_error_handler/error_reporter_spec.rb index a9fc088..298bd18 100644 --- a/spec/api_error_handler/error_reporter_spec.rb +++ b/spec/api_error_handler/error_reporter_spec.rb @@ -56,25 +56,47 @@ end end - context "using the :raven/:sentry strategy" do + context "using the :raven strategy" do let(:reporter) { described_class.new(:sentry) } it "Raises an error if the Raven constant is not defined" do expect { reporter.report(error) }.to raise_error(ApiErrorHandler::MissingDependencyError) end - it "Reports to Honeybadger with an error id" do + it "Reports to Sentry with an error id" do stub_const("Raven", double) expect(Raven).to receive(:capture_exception).with(error, extra: { error_id: "456" }) reporter.report(error, error_id: "456") end - it "Reports to Honeybadger without an error id" do + it "Reports to Sentry without an error id" do stub_const("Raven", double) expect(Raven).to receive(:capture_exception).with(error, extra: {}) reporter.report(error) end end + + context "using the :sentry strategy" do + let(:reporter) { described_class.new(:sentry) } + + it "Raises an error if the Sentry constant is not defined" do + expect { reporter.report(error) }.to raise_error(ApiErrorHandler::MissingDependencyError) + end + + it "Reports to Sentry with an error id" do + stub_const("Sentry", double) + expect(Sentry).to receive(:capture_exception).with(error, extra: { error_id: "456" }) + + reporter.report(error, error_id: "456") + end + + it "Reports to Sentry without an error id" do + stub_const("Sentry", double) + expect(Sentry).to receive(:capture_exception).with(error, extra: {}) + + reporter.report(error) + end + end end From 0c9e2973737869cb982ab99009bae0c4525d4fcf Mon Sep 17 00:00:00 2001 From: Hugo Correia Date: Wed, 31 Mar 2021 13:47:07 +0100 Subject: [PATCH 2/4] Fix wrong strategy in raven specs --- spec/api_error_handler/error_reporter_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api_error_handler/error_reporter_spec.rb b/spec/api_error_handler/error_reporter_spec.rb index 298bd18..080e146 100644 --- a/spec/api_error_handler/error_reporter_spec.rb +++ b/spec/api_error_handler/error_reporter_spec.rb @@ -57,7 +57,7 @@ end context "using the :raven strategy" do - let(:reporter) { described_class.new(:sentry) } + let(:reporter) { described_class.new(:raven) } it "Raises an error if the Raven constant is not defined" do expect { reporter.report(error) }.to raise_error(ApiErrorHandler::MissingDependencyError) From d439e6942dd1d60f95427f0936899488e4420842 Mon Sep 17 00:00:00 2001 From: James Stonehill Date: Tue, 9 Mar 2021 17:55:22 +0000 Subject: [PATCH 3/4] Add missing comma --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fedfbe6..bf0d213 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ you're using Rails with ActiveRecord, by default this includes: "ActionController::BadRequest" => :bad_request, "ActionController::ParameterMissing" => :bad_request, "Rack::QueryParser::ParameterTypeError" => :bad_request, - "Rack::QueryParser::InvalidParameterError" => :bad_request + "Rack::QueryParser::InvalidParameterError" => :bad_request, "ActiveRecord::RecordNotFound" => :not_found, "ActiveRecord::StaleObjectError" => :conflict, "ActiveRecord::RecordInvalid" => :unprocessable_entity, From e3a3d325f4fc2c0c389821bb2793469608cc637c Mon Sep 17 00:00:00 2001 From: Hugo Correia Date: Tue, 6 Apr 2021 14:03:40 +0100 Subject: [PATCH 4/4] Change version to 0.2.1 --- lib/api_error_handler/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api_error_handler/version.rb b/lib/api_error_handler/version.rb index 364e34c..1a4ea38 100644 --- a/lib/api_error_handler/version.rb +++ b/lib/api_error_handler/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ApiErrorHandler - VERSION = "0.3.0" + VERSION = "0.2.1" end