lib/spaceship/client.rb in spaceship-0.12.3 vs lib/spaceship/client.rb in spaceship-0.13.0
- old
+ new
@@ -31,10 +31,13 @@
# Raised when no user credentials were passed at all
class NoUserCredentialsError < StandardError; end
class UnexpectedResponse < StandardError; end
+ # Raised when 302 is received from portal request
+ class AppleTimeoutError < StandardError; end
+
# Authenticates with Apple's web services. This method has to be called once
# to generate a valid session. The session will automatically be used from then
# on.
#
# This method will automatically use the username from the Appfile (if available)
@@ -171,12 +174,13 @@
!!@cookie
end
def with_retry(tries = 5, &block)
return block.call
- rescue Faraday::Error::TimeoutError => ex # New Faraday version: Faraday::TimeoutError => ex
+ rescue Faraday::Error::TimeoutError, AppleTimeoutError => ex # New Faraday version: Faraday::TimeoutError => ex
unless (tries -= 1).zero?
+ logger.warn("Timeout received: '#{ex.message}'. Retrying after 3 seconds (remaining: #{tries})...")
sleep 3
retry
end
raise ex # re-raise the exception
@@ -238,10 +242,14 @@
# Actually sends the request to the remote server
# Automatically retries the request up to 3 times if something goes wrong
def send_request(method, url_or_path, params, headers, &block)
with_retry do
- @client.send(method, url_or_path, params, headers, &block)
+ response = @client.send(method, url_or_path, params, headers, &block)
+ if response.body.to_s.include?("<title>302 Found</title>")
+ raise AppleTimeoutError.new, "Apple 302 detected"
+ end
+ return response
end
end
def parse_response(response, expected_key = nil)
if expected_key