Skip to content

Commit 9d370e7

Browse files
tmm1Josh Holtz
authored andcommitted
[spaceship] also catch and handle "Gateway Timeout" (fastlane#13255)
* [spaceship] catch more internal server errors * Added new GatewayTimeoutError and tests for catching common errors
1 parent da9707e commit 9d370e7

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

spaceship/lib/spaceship/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Client
5050
UnexpectedResponse = Spaceship::UnexpectedResponse
5151
AppleTimeoutError = Spaceship::AppleTimeoutError
5252
UnauthorizedAccessError = Spaceship::UnauthorizedAccessError
53+
GatewayTimeoutError = Spaceship::GatewayTimeoutError
5354
InternalServerError = Spaceship::InternalServerError
5455

5556
# Authenticates with Apple's web services. This method has to be called once
@@ -532,6 +533,7 @@ def with_retry(tries = 5, &_block)
532533
Faraday::Error::TimeoutError,
533534
Faraday::ParsingError, # <h2>Internal Server Error</h2> with content type json
534535
AppleTimeoutError,
536+
GatewayTimeoutError,
535537
InternalServerError => ex # New Faraday version: Faraday::TimeoutError => ex
536538
tries -= 1
537539
unless tries.zero?
@@ -628,6 +630,8 @@ def detect_most_common_errors_and_raise_exceptions(body)
628630
raise_insuffient_permission_error!(caller_location: 3)
629631
elsif body.to_s.include?("Internal Server Error - Read")
630632
raise InternalServerError, "Received an internal server error from App Store Connect / Developer Portal, please try again later"
633+
elsif body.to_s.include?("Gateway Timeout - In read")
634+
raise GatewayTimeoutError, "Received a gateway timeout error from App Store Connect / Developer Portal, please try again later"
631635
elsif (body["resultString"] || "").include?("Program License Agreement")
632636
raise ProgramLicenseAgreementUpdated, "#{body['userString']} Please manually log into your Apple Developer account to review and accept the updated agreement."
633637
end

spaceship/lib/spaceship/errors.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ class UnauthorizedAccessError < BasicPreferredInfoError; end
7070

7171
# Raised when 500 is received from App Store Connect
7272
class InternalServerError < BasicPreferredInfoError; end
73+
74+
# Raised when 504 is received from App Store Connect
75+
class GatewayTimeoutError < BasicPreferredInfoError; end
7376
end

spaceship/spec/client_spec.rb

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,57 @@ def stub_client_retry_auth(status_error, times, status_ok, body)
3939
then.to_return(status: status_ok, body: body)
4040
end
4141

42+
describe 'detect_most_common_errors_and_raise_exceptions' do
43+
it "raises Spaceship::InsufficientPermissions for Forbidden" do
44+
body = JSON.generate({ messages: { error: "InsufficentPermissions" } })
45+
stub_client_request(Spaceship::InsufficientPermissions, 6, 200, body)
46+
47+
expect do
48+
subject.req_home
49+
end.to raise_error(Spaceship::InsufficientPermissions)
50+
end
51+
52+
it "raises Spaceship::InsufficientPermissions for insufficient privileges" do
53+
body = JSON.generate({ messages: { error: "insufficient privileges" } })
54+
stub_client_request(Spaceship::InsufficientPermissions, 6, 200, body)
55+
56+
expect do
57+
subject.req_home
58+
end.to raise_error(Spaceship::InsufficientPermissions)
59+
end
60+
61+
it "raises Spaceship::InternalServerError" do
62+
stub_client_request(Spaceship::GatewayTimeoutError, 6, 504, "<html>Internal Server - Read</html>")
63+
64+
expect do
65+
subject.req_home
66+
end.to raise_error(Spaceship::GatewayTimeoutError)
67+
end
68+
69+
it "raises Spaceship::GatewayTimeoutError" do
70+
stub_client_request(Spaceship::GatewayTimeoutError, 6, 504, "<html>Gateway Timeout - In Read</html>")
71+
72+
expect do
73+
subject.req_home
74+
end.to raise_error(Spaceship::GatewayTimeoutError)
75+
end
76+
77+
it "raises Spaceship::ProgramLicenseAgreementUpdated" do
78+
stub_client_request(Spaceship::ProgramLicenseAgreementUpdated, 6, 200, "Program License Agreement")
79+
80+
expect do
81+
subject.req_home
82+
end.to raise_error(Spaceship::ProgramLicenseAgreementUpdated)
83+
end
84+
end
85+
4286
describe 'retry' do
4387
[
4488
Faraday::Error::TimeoutError,
4589
Faraday::Error::ConnectionFailed,
46-
Faraday::ParsingError
90+
Faraday::ParsingError,
91+
Spaceship::InternalServerError,
92+
Spaceship::GatewayTimeoutError
4793
].each do |thrown|
4894
it "re-raises when retry limit reached throwing #{thrown}" do
4995
stub_client_request(thrown, 6, 200, nil)

0 commit comments

Comments
 (0)