Module: Mmailer::ErrorHandling

Includes:
Client
Included in:
MailHelper
Defined in:
lib/mmailer/error_handling.rb

Instance Method Summary collapse

Methods included from Client

#client

Instance Method Details

#try(number_of_times = 3) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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