Skip to content

Commit 0a22c89

Browse files
authored
Merge pull request #7 from aboutsource/feature/retry_on_connection_error
Retry API request on connection errors
2 parents ac221c7 + 8bd7081 commit 0a22c89

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

lib/quayio/scanner/repository.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ def api_call(uri)
2727
response = RestClient.get(
2828
"https://quay.io/api/v1/repository/#{org}/#{repo}#{uri}",
2929
authorization: "Bearer #{quayio_token}",
30-
accept: :json
30+
accept: :json,
31+
open_timeout: 15
3132
)
3233
return JSON.parse(response)
33-
rescue RestClient::ExceptionWithResponse => e
34-
raise e if e.http_code != 520 || attempt >= MAX_ATTEMPTS
34+
rescue RestClient::Exception => e
35+
raise e if attempt >= MAX_ATTEMPTS
36+
37+
# retry later, if we hit cdn rate limiting or on connection errors
38+
raise e unless e.http_code == 520 || e.http_code.nil?
3539

3640
sleep(rand(10))
3741
end

0 commit comments

Comments
 (0)