Skip to content

Commit

Permalink
Merge pull request #17 from hfcorreia/update-sentry-strategy-to-use-n…
Browse files Browse the repository at this point in the history
…ew-gem-version
  • Loading branch information
jamesstonehill authored Jul 5, 2021
2 parents 1500495 + dd070f4 commit c1635fd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/api_error_handler/error_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/api_error_handler/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ApiErrorHandler
VERSION = "0.2.0"
VERSION = "0.2.1"
end
30 changes: 26 additions & 4 deletions spec/api_error_handler/error_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,47 @@
end
end

context "using the :raven/:sentry strategy" do
let(:reporter) { described_class.new(:sentry) }
context "using the :raven strategy" do
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)
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

0 comments on commit c1635fd

Please sign in to comment.