Skip to content

Commit

Permalink
retry requests on failure (#1604)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhinavTuli committed Apr 18, 2022
1 parent 0424231 commit debc40a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions hub/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
)
from hub.client.log import logger

# for these codes, we will retry requests upto 3 times
retry_status_codes = {502}


class HubBackendClient:
"""Communicates with Activeloop Backend"""
Expand Down Expand Up @@ -91,22 +94,27 @@ def request(
headers = headers or {}
headers["hub-cli-version"] = self.version
headers["Authorization"] = self.auth_header
response = requests.request(
method,
request_url,
params=params,
data=data,
json=json,
headers=headers,
files=files,
timeout=timeout,
)

# clearer error than `ServerUnderMaintenence`
if json is not None and "password" in json and json["password"] is None:
# do NOT pass in the password here. `None` is explicitly typed.
raise InvalidPasswordException("Password cannot be `None`.")

status_code = None
tries = 0
while status_code is None or (status_code in retry_status_codes and tries < 3):
response = requests.request(
method,
request_url,
params=params,
data=data,
json=json,
headers=headers,
files=files,
timeout=timeout,
)
status_code = response.status_code
tries += 1
check_response_status(response)
return response

Expand Down

0 comments on commit debc40a

Please sign in to comment.