Skip to content

Commit

Permalink
Merge pull request #842 from parea-ai/fix-retry-on-read-error
Browse files Browse the repository at this point in the history
Fix retry on read error
  • Loading branch information
joschkabraun authored May 3, 2024
2 parents ee75a66 + c5ead11 commit 88f0902
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions parea/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def async_wrapper(*args, **kwargs):
for retry in range(MAX_RETRIES):
try:
return await func(*args, **kwargs)
except (httpx.HTTPStatusError, httpx.ConnectError) as e:
except httpx.HTTPError as e:
if not _should_retry(e, retry):
raise
await asyncio.sleep(BACKOFF_FACTOR * (2**retry))
Expand All @@ -40,7 +40,7 @@ def sync_wrapper(*args, **kwargs):
for retry in range(MAX_RETRIES):
try:
return func(*args, **kwargs)
except (httpx.HTTPStatusError, httpx.ConnectError) as e:
except httpx.HTTPError as e:
if not _should_retry(e, retry):
raise
time.sleep(BACKOFF_FACTOR * (2**retry))
Expand All @@ -49,7 +49,7 @@ def _should_retry(error, current_retry):
"""Determines if the function should retry on error."""
is_502_error = isinstance(error, httpx.HTTPStatusError) and error.response.status_code == 502
is_last_retry = current_retry == MAX_RETRIES - 1
return not is_last_retry and (isinstance(error, httpx.ConnectError) or is_502_error)
return not is_last_retry and (isinstance(error, (httpx.ConnectError, httpx.ReadError)) or is_502_error)

if asyncio.iscoroutinefunction(func):
return async_wrapper
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "parea-ai"
packages = [{ include = "parea" }]
version = "0.2.147"
version = "0.2.148"
description = "Parea python sdk"
readme = "README.md"
authors = ["joel-parea-ai <[email protected]>"]
Expand Down

0 comments on commit 88f0902

Please sign in to comment.