module Mmailer::ErrorHandling
Public Instance Methods
try(number_of_times=3) { || ... }
click to toggle source
# File lib/mmailer/error_handling.rb, line 5 def try(number_of_times=3) retry_count = 0 begin yield rescue Net::SMTPAuthenticationError => e puts "#{e.class}: #{e.message}" puts "This is a non-recoverable error. Please check your authentication credentials." client(:stop) rescue Net::OpenTimeout, Net::ReadTimeout, EOFError => e retry_count += 1 puts "#{e.class}: #{e.message}: #{retry_count} retries" sleep retry_count if retry_count < number_of_times retry else puts "Too many errors. Pausing mail queue." client(:pause) end nil rescue Net::SMTPUnknownError => e puts e.message client(:pause) end end