Files
openfoodnetwork/app/services/alert.rb
Maikel Linke 73a1698aad Add live test for Bugsnag
Needs human to review Bugsnag account.
2024-11-21 15:28:19 +11:00

32 lines
921 B
Ruby

# frozen_string_literal: true
# A handy wrapper around error reporting libraries like Bugsnag.
#
# Bugsnag's API is great for general purpose but overly complex for our use.
# It also changes over time and we often make mistakes using it. So this class
# aims at:
#
# * Abstracting from Bugsnag, open for other services.
# * Simpler interface to reduce user error.
# * Central place to update Bugsnag API usage when it changes.
#
class Alert
# Alert Bugsnag with additional metadata to appear in tabs.
#
# Alert.raise(
# "Invalid order during checkout",
# {
# order: { number: "ABC123", state: "awaiting_return" },
# env: { referer: "example.com" }
# }
# )
def self.raise(error, metadata = {}, &block)
Bugsnag.notify(error) do |payload|
metadata.each do |name, data|
payload.add_metadata(name, data)
end
block.call(payload)
end
end
end