From f00151ab78048537714dba82a4589acc7a8d87a9 Mon Sep 17 00:00:00 2001 From: jean-francois labbe Date: Mon, 28 Mar 2022 12:41:59 +0200 Subject: [PATCH] Document action mailer rescue_from Co-authored-by: Jonathan Hefner --- 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 a72542b70b21d..92546399b7c37 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