Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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