From bb37f7b263e997f3eb77f3f359e2b62c16bf45cc Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Tue, 30 Mar 2021 21:06:31 +0530 Subject: [PATCH] chore: Handle Sentry Errors (#2020) If a contract contains an invalid email address, the sidekiq jobs for conversation continuity would error out. handling this exception gracefully. --- app/mailers/application_mailer.rb | 7 +++++++ lib/exception_list.rb | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 12341e30c..9b5c876d6 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -16,12 +16,19 @@ class ApplicationMailer < ActionMailer::Base end end + rescue_from(*ExceptionList::SMTP_EXCEPTIONS, with: :handle_smtp_exceptions) + def smtp_config_set_or_development? ENV.fetch('SMTP_ADDRESS', nil).present? || Rails.env.development? end private + def handle_smtp_exceptions(message) + Rails.logger.info 'Failed to send Email' + Rails.logger.info "Exception: #{message}" + end + def send_mail_with_liquid(*args) mail(*args) do |format| # explored sending a multipart email containing both text type and html diff --git a/lib/exception_list.rb b/lib/exception_list.rb index 6ea285bd0..3909e4e22 100644 --- a/lib/exception_list.rb +++ b/lib/exception_list.rb @@ -1,5 +1,8 @@ module ExceptionList - URI_EXCEPTIONS = [Errno::ETIMEDOUT, Errno::ECONNREFUSED, URI::InvalidURIError, Net::OpenTimeout, SocketError].freeze + URI_EXCEPTIONS = [Errno::ETIMEDOUT, Errno::ECONNREFUSED, URI::InvalidURIError, Net::OpenTimeout, SocketError, OpenURI::HTTPError].freeze REST_CLIENT_EXCEPTIONS = [RestClient::NotFound, RestClient::GatewayTimeout, RestClient::BadRequest, - RestClient::MethodNotAllowed, RestClient::Forbidden].freeze + RestClient::MethodNotAllowed, RestClient::Forbidden, RestClient::InternalServerError, RestClient::PayloadTooLarge].freeze + SMTP_EXCEPTIONS = [ + Net::SMTPSyntaxError + ].freeze end