Skip to content

Commit c1635fd

Browse files
Merge pull request #17 from hfcorreia/update-sentry-strategy-to-use-new-gem-version
2 parents 1500495 + dd070f4 commit c1635fd

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

lib/api_error_handler/error_reporter.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ def report(error, error_id: nil)
1919

2020
context = error_id ? { error_id: error_id } : {}
2121
Honeybadger.notify(error, context: context)
22-
elsif @strategy == :raven || @strategy == :sentry
22+
elsif @strategy == :raven
2323
raise_dependency_error(missing_constant: "Raven") unless defined?(Raven)
2424

2525
extra = error_id ? { error_id: error_id } : {}
2626
Raven.capture_exception(error, extra: extra)
27+
elsif @strategy == :sentry
28+
raise_dependency_error(missing_constant: "Sentry") unless defined?(Sentry)
29+
30+
extra = error_id ? { error_id: error_id } : {}
31+
Sentry.capture_exception(error, extra: extra)
2732
else
2833
raise(
2934
InvalidOptionError,

lib/api_error_handler/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module ApiErrorHandler
4-
VERSION = "0.2.0"
4+
VERSION = "0.2.1"
55
end

spec/api_error_handler/error_reporter_spec.rb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,47 @@
5656
end
5757
end
5858

59-
context "using the :raven/:sentry strategy" do
60-
let(:reporter) { described_class.new(:sentry) }
59+
context "using the :raven strategy" do
60+
let(:reporter) { described_class.new(:raven) }
6161

6262
it "Raises an error if the Raven constant is not defined" do
6363
expect { reporter.report(error) }.to raise_error(ApiErrorHandler::MissingDependencyError)
6464
end
6565

66-
it "Reports to Honeybadger with an error id" do
66+
it "Reports to Sentry with an error id" do
6767
stub_const("Raven", double)
6868
expect(Raven).to receive(:capture_exception).with(error, extra: { error_id: "456" })
6969

7070
reporter.report(error, error_id: "456")
7171
end
7272

73-
it "Reports to Honeybadger without an error id" do
73+
it "Reports to Sentry without an error id" do
7474
stub_const("Raven", double)
7575
expect(Raven).to receive(:capture_exception).with(error, extra: {})
7676

7777
reporter.report(error)
7878
end
7979
end
80+
81+
context "using the :sentry strategy" do
82+
let(:reporter) { described_class.new(:sentry) }
83+
84+
it "Raises an error if the Sentry constant is not defined" do
85+
expect { reporter.report(error) }.to raise_error(ApiErrorHandler::MissingDependencyError)
86+
end
87+
88+
it "Reports to Sentry with an error id" do
89+
stub_const("Sentry", double)
90+
expect(Sentry).to receive(:capture_exception).with(error, extra: { error_id: "456" })
91+
92+
reporter.report(error, error_id: "456")
93+
end
94+
95+
it "Reports to Sentry without an error id" do
96+
stub_const("Sentry", double)
97+
expect(Sentry).to receive(:capture_exception).with(error, extra: {})
98+
99+
reporter.report(error)
100+
end
101+
end
80102
end

0 commit comments

Comments
 (0)