mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-06 07:29:16 +00:00
Report simple values easily
This commit is contained in:
@@ -22,11 +22,16 @@ class Alert
|
||||
# )
|
||||
def self.raise(error, metadata = {}, &block)
|
||||
Bugsnag.notify(error) do |payload|
|
||||
unless metadata.respond_to?(:each)
|
||||
metadata = { metadata: { data: metadata } }
|
||||
end
|
||||
|
||||
metadata.each do |name, data|
|
||||
# Bugsnag only reports metadata when given a Hash.
|
||||
data = { data: } unless data.is_a?(Hash)
|
||||
payload.add_metadata(name, data)
|
||||
end
|
||||
|
||||
block.call(payload)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,6 +49,14 @@ RSpec.describe Alert do
|
||||
Alert.raise("hey", data: "ABC123")
|
||||
end
|
||||
|
||||
it "adds simple values as context" do
|
||||
expect_any_instance_of(Bugsnag::Report).to receive(:add_metadata).with(
|
||||
:metadata, { data: "ABC123" }
|
||||
)
|
||||
|
||||
Alert.raise("hey", "ABC123")
|
||||
end
|
||||
|
||||
it "is compatible with Bugsnag API" do
|
||||
expect_any_instance_of(Bugsnag::Report).to receive(:add_metadata).with(
|
||||
:order, { number: "ABC123" }
|
||||
|
||||
Reference in New Issue
Block a user