Skip to content

Commit a810910

Browse files
committed
refactor: Inline permanent-error classification at retry call sites
1 parent 92cbd92 commit a810910

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

‎src/apify_client/http_clients/_impit.py‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ def _is_retryable_error(exc: Exception) -> bool:
5454
)
5555

5656

57-
def _stop_retrying_if_permanent(exc: Exception, *, stop_retrying: Callable[[], None]) -> None:
58-
"""Stop the retry loop when an exception is not a transient transport failure."""
59-
if not _is_retryable_error(exc):
60-
logger.debug('Exception is not retryable', exc_info=exc)
61-
stop_retrying()
62-
63-
6457
@docs_group('HTTP clients')
6558
class ImpitHttpClient(HttpClient):
6659
"""Synchronous HTTP client for the Apify API built on top of [Impit](https://github.com/apify/impit).
@@ -240,7 +233,9 @@ def _make_request(
240233

241234
except Exception as exc:
242235
logger.debug('Request threw exception', exc_info=exc)
243-
_stop_retrying_if_permanent(exc, stop_retrying=stop_retrying)
236+
if not _is_retryable_error(exc):
237+
logger.debug('Exception is not retryable', exc_info=exc)
238+
stop_retrying()
244239
raise
245240

246241
# Retry only server errors (5xx) and rate limits (429).
@@ -260,7 +255,9 @@ def _make_request(
260255
logger.debug('Reading the error response failed', exc_info=exc)
261256
with suppress(Exception):
262257
response.close()
263-
_stop_retrying_if_permanent(exc, stop_retrying=stop_retrying)
258+
if not _is_retryable_error(exc):
259+
logger.debug('Exception is not retryable', exc_info=exc)
260+
stop_retrying()
264261
raise
265262

266263
raise ApifyApiError(response, attempt, method=method)
@@ -509,7 +506,9 @@ async def _make_request(
509506

510507
except Exception as exc:
511508
logger.debug('Request threw exception', exc_info=exc)
512-
_stop_retrying_if_permanent(exc, stop_retrying=stop_retrying)
509+
if not _is_retryable_error(exc):
510+
logger.debug('Exception is not retryable', exc_info=exc)
511+
stop_retrying()
513512
raise
514513

515514
# Retry only server errors (5xx) and rate limits (429).
@@ -529,7 +528,9 @@ async def _make_request(
529528
logger.debug('Reading the error response failed', exc_info=exc)
530529
with suppress(Exception):
531530
await response.aclose()
532-
_stop_retrying_if_permanent(exc, stop_retrying=stop_retrying)
531+
if not _is_retryable_error(exc):
532+
logger.debug('Exception is not retryable', exc_info=exc)
533+
stop_retrying()
533534
raise
534535

535536
raise ApifyApiError(response, attempt, method=method)

0 commit comments

Comments
 (0)