diff options
Diffstat (limited to 'lib/chef/http.rb')
-rw-r--r-- | lib/chef/http.rb | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb index bf2316113e..abc47f636e 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -62,6 +62,7 @@ class Chef end + def self.middlewares @middlewares ||= [] end @@ -281,34 +282,18 @@ class Chef end end + # Wraps an HTTP request with retry logic. # === Arguments # url:: URL of the request, used for error messages def retrying_http_errors(url) http_attempts = 0 begin - loop do - http_attempts += 1 - - response, request, return_value = yield - - if response.kind_of?(Net::HTTPServerError) - if http_retry_count >= http_attempts - Chef::Log.error("Error connecting to #{url} - #{response.code}, retry #{http_attempts}/#{http_retry_count}") - sleep(http_retry_delay) - redo - end - end + http_attempts += 1 - return [response, request, return_value] - end + yield rescue SocketError, Errno::ETIMEDOUT => e - if http_retry_count - http_attempts + 1 > 0 - Chef::Log.error("Error connecting to #{url} - #{e.message}, retry #{http_attempts}/#{http_retry_count}") - sleep(http_retry_delay) - retry - end e.message.replace "Error connecting to #{url} - #{e.message}" raise e rescue Errno::ECONNREFUSED @@ -395,6 +380,7 @@ class Chef raise end + public ############################################################################ |