amelioration(Dolist::ApiSender): lève une Dolist::IgnorableError afin de l'inscrire dans l'historique des EmailEvent
This commit is contained in:
parent
8fa2bbb67d
commit
534ce34f87
3 changed files with 25 additions and 9 deletions
|
@ -154,6 +154,18 @@ class Dolist::API
|
||||||
post(url, body)["FieldList"].find { _1['ID'] == 72 }['Value']
|
post(url, body)["FieldList"].find { _1['ID'] == 72 }['Value']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ignorable_error?(response, mail)
|
||||||
|
error_code = response&.dig("ResponseStatus", "ErrorCode")
|
||||||
|
invalid_contact_status = if ignorable_api_error_code?(error_code)
|
||||||
|
fetch_contact_status(mail.to.first)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
[error_code, invalid_contact_status]
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def ignorable_api_error_code?(api_error_code)
|
def ignorable_api_error_code?(api_error_code)
|
||||||
IGNORABLE_API_ERROR_CODE.include?(api_error_code)
|
IGNORABLE_API_ERROR_CODE.include?(api_error_code)
|
||||||
end
|
end
|
||||||
|
@ -162,8 +174,6 @@ class Dolist::API
|
||||||
IGNORABLE_CONTACT_STATUSES.include?(contact_status)
|
IGNORABLE_CONTACT_STATUSES.include?(contact_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def format_url(base)
|
def format_url(base)
|
||||||
format(base, account_id: account_id)
|
format(base, account_id: account_id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,12 +19,18 @@ module MailerMonitoringConcern
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue_from Dolist::IgnorableError, with: :log_delivery_error
|
||||||
|
|
||||||
def log_and_raise_delivery_error(exception)
|
def log_and_raise_delivery_error(exception)
|
||||||
EmailEvent.create_from_message!(message, status: "dispatch_error")
|
log_delivery_error(exception)
|
||||||
Sentry.capture_exception(exception, extra: { to: message.to, subject: message.subject })
|
Sentry.capture_exception(exception, extra: { to: message.to, subject: message.subject })
|
||||||
|
|
||||||
# re-raise another error so job will retry later
|
# re-raise another error so job will retry later
|
||||||
raise MailDeliveryError.new(exception)
|
raise MailDeliveryError.new(exception)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_delivery_error(exception)
|
||||||
|
EmailEvent.create_from_message!(message, status: "dispatch_error")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
ActiveSupport.on_load(:action_mailer) do
|
ActiveSupport.on_load(:action_mailer) do
|
||||||
module Dolist
|
module Dolist
|
||||||
|
class IgnorableError < StandardError
|
||||||
|
end
|
||||||
|
|
||||||
class SMTP < ::Mail::SMTP
|
class SMTP < ::Mail::SMTP
|
||||||
def deliver!(mail)
|
def deliver!(mail)
|
||||||
mail.from(ENV['DOLIST_NO_REPLY_EMAIL'])
|
mail.from(ENV['DOLIST_NO_REPLY_EMAIL'])
|
||||||
|
@ -20,14 +23,11 @@ ActiveSupport.on_load(:action_mailer) do
|
||||||
if response&.dig("Result")
|
if response&.dig("Result")
|
||||||
mail.message_id = response.dig("Result")
|
mail.message_id = response.dig("Result")
|
||||||
else
|
else
|
||||||
error_code = response&.dig("ResponseStatus", "ErrorCode")
|
_, invalid_contact_status = client.ignorable_error?(response, mail)
|
||||||
|
|
||||||
contact_status = if client.ignorable_api_error_code?(error_code)
|
if invalid_contact_status
|
||||||
client.fetch_contact_status(mail.to.first)
|
raise Dolist::IgnorableError.new("DoList delivery error. contact unreachable: #{invalid_contact_status}")
|
||||||
else
|
else
|
||||||
nil
|
|
||||||
end
|
|
||||||
if !client.ignorable_contact_status?(contact_status)
|
|
||||||
fail "DoList delivery error. Body: #{response}"
|
fail "DoList delivery error. Body: #{response}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue