refactor(email): log event when error occurs before recipients was set
This commit is contained in:
parent
1f51267b25
commit
5ae5de0d9c
3 changed files with 5 additions and 9 deletions
|
@ -20,12 +20,8 @@ module MailerErrorConcern
|
|||
protected
|
||||
|
||||
def log_delivery_error(exception)
|
||||
if defined?(message) && message.to.present?
|
||||
EmailEvent.create_from_message!(message, status: "dispatch_error")
|
||||
Sentry.capture_exception(exception, extra: { to: message&.to, subject: message&.subject })
|
||||
else
|
||||
Sentry.capture_exception(exception)
|
||||
end
|
||||
Sentry.capture_exception(exception, extra: { to: message.to, subject: message.subject })
|
||||
|
||||
# TODO find a way to re attempt the job
|
||||
end
|
||||
|
|
|
@ -19,7 +19,9 @@ class EmailEvent < ApplicationRecord
|
|||
|
||||
class << self
|
||||
def create_from_message!(message, status:)
|
||||
message.to.each do |recipient|
|
||||
to = message.to || ["unset"] # no recipients when error occurs *before* setting to: in the mailer
|
||||
|
||||
to.each do |recipient|
|
||||
EmailEvent.create!(
|
||||
to: pseudonymize_email(recipient),
|
||||
subject: message.subject,
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
class EmailDeliveryObserver
|
||||
def self.delivered_email(message)
|
||||
return if message.to.nil?
|
||||
|
||||
EmailEvent.create_from_message!(message, status: "dispatched")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue