class Racli::Handlers::RetryHandler

Constants

DEFAULT_MAX_RETRY_COUNTER

Attributes

default_max_retry_counter[RW]
retry_counter[RW]

Public Class Methods

new(cli) click to toggle source
Calls superclass method Racli::Handlers::Base::new
# File lib/racli/handlers/retry_handler.rb, line 12
def initialize(cli)
  @retry_counter = 0
  @retry_max_counter = DEFAULT_MAX_RETRY_COUNTER
  super
end

Public Instance Methods

call(status, headers, body, original_args) click to toggle source
# File lib/racli/handlers/retry_handler.rb, line 18
def call(status, headers, body, original_args)
  if (300...400).cover?(status.to_i) && headers['Location']
    unless within_max_retry_count?
      STDERR.puts 'Too many redirection!'
      throw :abort
    end
    @retry_counter += 1
    original_args[:method] = 'GET'
    original_args[:path]   = headers['Location']
    cli.call(**original_args)
    throw :abort
  end
  [status, headers, body]
end
within_max_retry_count?() click to toggle source
# File lib/racli/handlers/retry_handler.rb, line 33
def within_max_retry_count?
  @retry_counter < DEFAULT_MAX_RETRY_COUNTER
end