Module: Grocer::ErrorCallback::Connection

Defined in:
lib/grocer/error_callback/connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
# File 'lib/grocer/error_callback/connection.rb', line 2

def self.included(base)
  base.class_eval do
    remove_method :with_connection
  end
end

Instance Method Details

#with_connectionObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/grocer/error_callback/connection.rb', line 8

def with_connection
  attempts = 1
  begin
    connect
    yield
  rescue => e
    if e.class == OpenSSL::SSL::SSLError && e.message =~ /certificate expired/i
      e.extend(CertificateExpiredError)
      raise
    end

    run_callbacks :connection_error, e

    raise unless attempts < retries

    destroy_connection
    attempts += 1
    retry
  end
end