Class: BarsoomUtils::ExceptionNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/barsoom_utils/exception_notifier.rb

Class Method Summary collapse

Class Method Details

.message(message, details_or_context = nil, context_or_nothing = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/barsoom_utils/exception_notifier.rb', line 19

def self.message(message, details_or_context = nil, context_or_nothing = nil)
  if context_or_nothing
    details = details_or_context
    context = context_or_nothing
  elsif details_or_context.is_a?(Hash)
    details = nil
    context = details_or_context
  else
    details = details_or_context
    context = {}
  end

  result = Honeybadger.notify(
    error_class: message,
    error_message: (details || "(no message)").to_s,
    context: context.to_h,
  )

  if defined?(Sentry)
    title = details ? "#{message}: #{details}" : message.to_s
    Sentry.capture_message(title, extra: context.to_h)
  end

  result
end

.notify(exception, context: {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/barsoom_utils/exception_notifier.rb', line 7

def self.notify(exception, context: {})
  # Inelegant workaround for the fact that we've confused this method with .message at least once.
  # TODO: Fold them into a single method?
  unless exception.is_a?(Exception)
    raise "Expected an exception but got: #{exception.inspect}"
  end

  result = Honeybadger.notify(exception, context: context)
  Sentry.capture_exception(exception, extra: context) if defined?(Sentry)
  result
end