Skip to content

Commit 6d96f53

Browse files
committed
move is_retryable_error in utils
1 parent 7055c74 commit 6d96f53

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/apify_client/_http_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
from apify_client._logging import log_context, logger_name
1616
from apify_client._statistics import Statistics
17-
from apify_client._utils import retry_with_exp_backoff, retry_with_exp_backoff_async
18-
from apify_client.errors import ApifyApiError, InvalidResponseBodyError, is_retryable_error
17+
from apify_client._utils import is_retryable_error, retry_with_exp_backoff, retry_with_exp_backoff_async
18+
from apify_client.errors import ApifyApiError, InvalidResponseBodyError
1919

2020
if TYPE_CHECKING:
2121
from collections.abc import Callable

src/apify_client/_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
from http import HTTPStatus
1010
from typing import TYPE_CHECKING, Any, TypeVar, cast
1111

12+
import httpx
1213
from apify_shared.utils import is_file_or_bytes, maybe_extract_enum_member_value
1314

15+
from apify_client.errors import InvalidResponseBodyError
16+
1417
if TYPE_CHECKING:
1518
from collections.abc import Awaitable
1619

@@ -149,3 +152,16 @@ def encode_key_value_store_record_value(value: Any, content_type: str | None = N
149152
value = json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False, default=str).encode('utf-8')
150153

151154
return (value, content_type)
155+
156+
157+
def is_retryable_error(exc: Exception) -> bool:
158+
"""Check if the given error is retryable."""
159+
return isinstance(
160+
exc,
161+
(
162+
InvalidResponseBodyError,
163+
httpx.NetworkError,
164+
httpx.TimeoutException,
165+
httpx.RemoteProtocolError,
166+
),
167+
)

src/apify_client/errors.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from __future__ import annotations
22

3-
import httpx
3+
from typing import TYPE_CHECKING
4+
45
from apify_shared.utils import ignore_docs
56

7+
if TYPE_CHECKING:
8+
import httpx
9+
610

711
class ApifyClientError(Exception):
812
"""Base class for errors specific to the Apify API Client."""
@@ -72,16 +76,3 @@ def __init__(self, response: httpx.Response) -> None:
7276
self.name = 'InvalidResponseBodyError'
7377
self.code = 'invalid-response-body'
7478
self.response = response
75-
76-
77-
def is_retryable_error(exc: Exception) -> bool:
78-
"""Check if the given error is retryable."""
79-
return isinstance(
80-
exc,
81-
(
82-
InvalidResponseBodyError,
83-
httpx.NetworkError,
84-
httpx.TimeoutException,
85-
httpx.RemoteProtocolError,
86-
),
87-
)

0 commit comments

Comments
 (0)