Module: LogStruct::Integrations::ActionMailer::ErrorHandling

Extended by:
ActiveSupport::Concern, T::Sig
Defined in:
lib/log_struct/integrations/action_mailer/error_handling.rb

Overview

Handles error handling for ActionMailer

IMPORTANT LIMITATIONS:

  1. This module must be included BEFORE users define rescue_from handlers to ensure proper handler precedence (user handlers are checked first)
  2. Rails rescue_from handlers don't bubble to parent class handlers after reraise
  3. Handler order matters: Rails checks rescue_from handlers in reverse declaration order

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#logstruct_mail_failedBoolean?

Returns:

  • (Boolean, nil)


19
20
21
# File 'lib/log_struct/integrations/action_mailer/error_handling.rb', line 19

def logstruct_mail_failed
  @logstruct_mail_failed
end

Class Method Details

.install_handler(base) ⇒ void

This method returns an undefined value.

This will be called when the module is included/prepended

Parameters:

  • base (T.untyped)


27
28
29
30
31
32
33
34
35
36
# File 'lib/log_struct/integrations/action_mailer/error_handling.rb', line 27

def self.install_handler(base)
  # Only add the handler once per class
  return if base.instance_variable_get(:@_logstruct_handler_installed)

  # Add our handler FIRST so it has lower priority than user handlers
  base.rescue_from StandardError, with: :log_and_reraise_error

  # Mark as installed to prevent duplicates
  base.instance_variable_set(:@_logstruct_handler_installed, true)
end

.prepended(base) ⇒ void

This method returns an undefined value.

Also support prepended (used by tests and manual setup)

Parameters:

  • base (T.untyped)


44
45
46
# File 'lib/log_struct/integrations/action_mailer/error_handling.rb', line 44

def self.prepended(base)
  install_handler(base)
end

Instance Method Details

#log_and_ignore_error(ex) ⇒ void (protected)

This method returns an undefined value.

Just log the error without reporting or retrying

Parameters:

  • ex (StandardError)


52
53
54
55
# File 'lib/log_struct/integrations/action_mailer/error_handling.rb', line 52

def log_and_ignore_error(ex)
  self.logstruct_mail_failed = true
  log_email_delivery_error(ex, notify: false, report: false, reraise: false)
end

#log_and_report_error(ex) ⇒ void (protected)

This method returns an undefined value.

Log and report to error service, but doesn't reraise.

Parameters:

  • ex (StandardError)


59
60
61
# File 'lib/log_struct/integrations/action_mailer/error_handling.rb', line 59

def log_and_report_error(ex)
  log_email_delivery_error(ex, notify: false, report: true, reraise: false)
end

#log_and_reraise_error(ex) ⇒ void (protected)

This method returns an undefined value.

Log, report to error service, and reraise for retry

Parameters:

  • ex (StandardError)


65
66
67
# File 'lib/log_struct/integrations/action_mailer/error_handling.rb', line 65

def log_and_reraise_error(ex)
  log_email_delivery_error(ex, notify: false, report: true, reraise: true)
end