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
|
protected
|
||||||
|
|
||||||
def log_delivery_error(exception)
|
def log_delivery_error(exception)
|
||||||
if defined?(message) && message.to.present?
|
EmailEvent.create_from_message!(message, status: "dispatch_error")
|
||||||
EmailEvent.create_from_message!(message, status: "dispatch_error")
|
Sentry.capture_exception(exception, extra: { to: message.to, subject: message.subject })
|
||||||
Sentry.capture_exception(exception, extra: { to: message&.to, subject: message&.subject })
|
|
||||||
else
|
|
||||||
Sentry.capture_exception(exception)
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO find a way to re attempt the job
|
# TODO find a way to re attempt the job
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,9 @@ class EmailEvent < ApplicationRecord
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def create_from_message!(message, status:)
|
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!(
|
EmailEvent.create!(
|
||||||
to: pseudonymize_email(recipient),
|
to: pseudonymize_email(recipient),
|
||||||
subject: message.subject,
|
subject: message.subject,
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
class EmailDeliveryObserver
|
class EmailDeliveryObserver
|
||||||
def self.delivered_email(message)
|
def self.delivered_email(message)
|
||||||
return if message.to.nil?
|
|
||||||
|
|
||||||
EmailEvent.create_from_message!(message, status: "dispatched")
|
EmailEvent.create_from_message!(message, status: "dispatched")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue