Class: RailsErrorNotifier::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_notifier/notifier.rb

Constant Summary collapse

MAX_FIELD_VALUE =
1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, context = {}) ⇒ Notifier

Returns a new instance of Notifier.



16
17
18
19
# File 'lib/rails_error_notifier/notifier.rb', line 16

def initialize(exception, context = {})
  @exception = exception
  @context   = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



14
15
16
# File 'lib/rails_error_notifier/notifier.rb', line 14

def context
  @context
end

#exceptionObject (readonly)

Returns the value of attribute exception.



14
15
16
# File 'lib/rails_error_notifier/notifier.rb', line 14

def exception
  @exception
end

Instance Method Details

#deliverObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rails_error_notifier/notifier.rb', line 21

def deliver
  return unless RailsErrorNotifier.configuration&.enabled
  app_trace = (exception.backtrace || []).select { |line| line.to_s.include?("/app/") }

  payload = {
    error: exception.message,
    backtrace:  app_trace.presence || exception.backtrace || ["No backtrace"],
    context: context || {}
  }

  # Slack + Discord
  send_to_webhook(RailsErrorNotifier.configuration.slack_webhook, payload)
  send_to_webhook(RailsErrorNotifier.configuration.discord_webhook, payload)

  # Email (Rails Mailer)
  send_to_email(payload)

  # WhatsApp (Twilio)
  send_to_whatsapp(payload)
end