From ae98f492ca001f0b7879453dcd57877325608977 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Tue, 3 May 2022 10:47:38 -0500 Subject: [PATCH] Merge pull request #44777 from jean-francois-labbe/main Document action mailer rescue_from [ci-skip] (cherry picked from commit e4ec2cbb494f6ec7dda227b05ba8a1ec8675c796) --- actionmailer/lib/action_mailer/base.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 09fc9a35b57f3..ad733e31fe30f 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -342,6 +342,29 @@ module ActionMailer # using before_action rather than after_action in your # Action Mailer classes so that headers are parsed properly. # + # = Rescuing Errors + # + # +rescue+ blocks inside of a mailer method cannot rescue errors that occur + # outside of rendering -- for example, record deserialization errors in a + # background job, or errors from a third-party mail delivery service. + # + # To rescue errors that occur during any part of the mailing process, use + # {rescue_from}[rdoc-ref:ActiveSupport::Rescuable::ClassMethods#rescue_from]: + # + # class NotifierMailer < ApplicationMailer + # rescue_from ActiveJob::DeserializationError do + # # ... + # end + # + # rescue_from "SomeThirdPartyService::ApiError" do + # # ... + # end + # + # def notify(recipient) + # mail(to: recipient, subject: "Notification") + # end + # end + # # = Previewing emails # # You can preview your email templates visually by adding a mailer preview file to the