Skip to content

Commit 775a326

Browse files
authored
Merge pull request #660 from superannotateai/FRIDAY-2368
fix AIOHttpSession retry
2 parents e2f309b + 59f3638 commit 775a326

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/superannotate/lib/infrastructure/services/http_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import aiohttp
1515
import requests
16+
from aiohttp.client_exceptions import ClientError
1617
from lib.core.exceptions import AppException
1718
from lib.core.service_types import ServiceResponse
1819
from lib.core.serviceproviders import BaseClient
@@ -197,7 +198,7 @@ def serialize_response(
197198
if not response.ok:
198199
if response.status_code in (502, 504):
199200
data[
200-
"_error"
201+
"res_error"
201202
] = "Our service is currently unavailable, please try again later."
202203
return content_type(**data)
203204
else:
@@ -234,7 +235,13 @@ async def request(self, *args, **kwargs) -> aiohttp.ClientResponse:
234235
for _ in range(attempts):
235236
delay += self.BACKOFF_FACTOR
236237
attempts -= 1
237-
response = await super()._request(*args, **kwargs)
238+
try:
239+
response = await super()._request(*args, **kwargs)
240+
except ClientError:
241+
if not attempts:
242+
raise
243+
await asyncio.sleep(delay)
244+
continue
238245
if response.status not in self.RETRY_STATUS_CODES or not attempts:
239246
return response
240247
await asyncio.sleep(delay)

0 commit comments

Comments
 (0)