diff --git a/lib/shopify_api/connection.rb b/lib/shopify_api/connection.rb index e272418bf..af0ebcf09 100644 --- a/lib/shopify_api/connection.rb +++ b/lib/shopify_api/connection.rb @@ -32,11 +32,19 @@ def notify_about_request(response, arguments) module RedoIfTemporaryError def request(*args) + binding.pry super rescue ActiveResource::ClientError, ActiveResource::ServerError => e if should_retry? && e.response.class.in?([Net::HTTPTooManyRequests, Net::HTTPInternalServerError]) - wait - request *args + if e.response.class.in?([Net::HTTPTooManyRequests]) + wait + request *args + else + sleep 30 + increase_server_error_counter + raise if server_error_counter == 10 + request *args + end else raise end @@ -49,6 +57,14 @@ def wait def should_retry? [true, nil].include? Thread.current[:retry_temporary_errors] end + + def increase_server_error_counter + @server_error_counter = server_error_counter + 1 + end + + def server_error_counter + @server_error_counter ||= 0 + end end include RedoIfTemporaryError