Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/superannotate/lib/infrastructure/services/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import aiohttp
import requests
from aiohttp.client_exceptions import ClientError
from lib.core.exceptions import AppException
from lib.core.service_types import ServiceResponse
from lib.core.serviceproviders import BaseClient
Expand Down Expand Up @@ -197,7 +198,7 @@ def serialize_response(
if not response.ok:
if response.status_code in (502, 504):
data[
"_error"
"res_error"
] = "Our service is currently unavailable, please try again later."
return content_type(**data)
else:
Expand Down Expand Up @@ -234,7 +235,13 @@ async def request(self, *args, **kwargs) -> aiohttp.ClientResponse:
for _ in range(attempts):
delay += self.BACKOFF_FACTOR
attempts -= 1
response = await super()._request(*args, **kwargs)
try:
response = await super()._request(*args, **kwargs)
except ClientError:
if not attempts:
raise
await asyncio.sleep(delay)
continue
if response.status not in self.RETRY_STATUS_CODES or not attempts:
return response
await asyncio.sleep(delay)