Class: Faraday::Request::Retry

Inherits:
Middleware show all
Defined in:
lib/faraday/request/retry.rb

Instance Method Summary collapse

Methods inherited from Middleware

dependency, inherited, loaded?, new

Methods included from MiddlewareRegistry

#lookup_middleware, #register_middleware

Constructor Details

#initialize(app, retries = 2) ⇒ Retry

Returns a new instance of Retry.



3
4
5
6
# File 'lib/faraday/request/retry.rb', line 3

def initialize(app, retries = 2)
  @retries = retries
  super(app)
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/faraday/request/retry.rb', line 8

def call(env)
  retries = @retries
  begin
    @app.call(env)
  rescue StandardError, Timeout::Error
    if retries > 0
      retries -= 1
      retry
    end
    raise
  end
end