Class: Excon::Middleware::Idempotent

Inherits:
Base
  • Object
show all
Defined in:
lib/excon/middlewares/idempotent.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #request_call, #response_call

Constructor Details

This class inherits a constructor from Excon::Middleware::Base

Instance Method Details

#error_call(datum) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/excon/middlewares/idempotent.rb', line 4

def error_call(datum)
  if datum[:idempotent]
    if datum.has_key?(:request_block)
      if datum[:request_block].respond_to?(:rewind)
        datum[:request_block].rewind
      else
        Excon.display_warning('Excon requests with a :request_block must implement #rewind in order to be :idempotent.')
        datum[:idempotent] = false
      end
    end
    if datum.has_key?(:pipeline)
      Excon.display_warning("Excon requests can not be :idempotent when pipelining.")
      datum[:idempotent] = false
    end
  end

  if datum[:idempotent] && [Excon::Errors::Timeout, Excon::Errors::SocketError,
      Excon::Errors::HTTPStatusError].any? {|ex| datum[:error].kind_of?(ex) } && datum[:retries_remaining] > 1
    # reduces remaining retries, reset connection, and restart request_call
    datum[:retries_remaining] -= 1
    connection = datum.delete(:connection)
    datum.reject! {|key, _| !Excon::VALID_REQUEST_KEYS.include?(key) }
    connection.request(datum)
  else
    @stack.error_call(datum)
  end
end