|
|
@@ -14,6 +14,7 @@ from tenacity import (
|
|
|
)
|
|
|
from urllib3.exceptions import IncompleteRead
|
|
|
|
|
|
+from openhands.core.logger import openhands_logger as logger
|
|
|
from openhands.utils.tenacity_stop import stop_if_should_exit
|
|
|
|
|
|
|
|
|
@@ -31,6 +32,13 @@ def is_404_error(exception):
|
|
|
)
|
|
|
|
|
|
|
|
|
+def is_429_error(exception):
|
|
|
+ return (
|
|
|
+ isinstance(exception, requests.HTTPError)
|
|
|
+ and exception.response.status_code == 429
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
def is_503_error(exception):
|
|
|
return (
|
|
|
isinstance(exception, requests.HTTPError)
|
|
|
@@ -76,6 +84,9 @@ def send_request_with_retry(
|
|
|
wait=wait_exponential(multiplier=1, min=4, max=20),
|
|
|
retry=retry_condition,
|
|
|
reraise=True,
|
|
|
+ before_sleep=lambda retry_state: logger.debug(
|
|
|
+ f'Retrying {method} request to {url} due to {retry_state.outcome.exception()}. Attempt {retry_state.attempt_number}'
|
|
|
+ ),
|
|
|
)
|
|
|
def _send_request_with_retry():
|
|
|
response = session.request(method, url, **kwargs)
|