delay_retry(context)
click to toggle source
def delay_retry(context)
context.config.retry_backoff.call(context)
end
error_for(response)
click to toggle source
def error_for(response)
status_code = response.context.http_response.status_code
ErrorInspector.new(response.error, status_code)
end
refreshable_credentials?(context)
click to toggle source
def refreshable_credentials?(context)
context.config.credentials.respond_to?(:refresh!)
end
response_truncatable?(context)
click to toggle source
def response_truncatable?(context)
context.http_response.body.respond_to?(:truncate)
end
retry_if_possible(response)
click to toggle source
def retry_if_possible(response)
context = response.context
error = error_for(response)
if should_retry?(context, error)
retry_request(context, error)
else
response
end
end
retry_limit(context)
click to toggle source
def retry_limit(context)
context.config.retry_limit
end
retry_request(context, error)
click to toggle source
def retry_request(context, error)
delay_retry(context)
context.retries += 1
context.config.credentials.refresh! if error.expired_credentials?
context.http_request.body.rewind
context.http_response.reset
call(context)
end
retryable?(context, error)
click to toggle source
def retryable?(context, error)
(error.expired_credentials? and refreshable_credentials?(context)) or
error.throttling_error? or
error.checksum? or
error.networking? or
error.server?
end
should_retry?(context, error)
click to toggle source
def should_retry?(context, error)
retryable?(context, error) and
context.retries < retry_limit(context) and
response_truncatable?(context)
end