chore: try catch around retry error (#77)

pull/82/head v0.1.3
Laurel Orr 1 year ago committed by GitHub
parent 0fb192a0a2
commit f2e6ec9984

@ -4,7 +4,7 @@ import copy
import logging import logging
import math import math
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional, Tuple, Union from typing import Any, Dict, List, Optional, Tuple, Union, cast
import aiohttp import aiohttp
import requests import requests
@ -18,9 +18,15 @@ logger = logging.getLogger(__name__)
def retry_if_ratelimit(retry_base: RetryCallState) -> bool: def retry_if_ratelimit(retry_base: RetryCallState) -> bool:
"""Return whether to retry if ratelimited.""" """Return whether to retry if ratelimited."""
if isinstance(retry_base.outcome.exception(), requests.exceptions.HTTPError): try:
if retry_base.outcome.exception().response.status_code == 429: # type: ignore if isinstance(retry_base.outcome.exception(), requests.exceptions.HTTPError):
return True exception = cast(
requests.exceptions.HTTPError, retry_base.outcome.exception()
)
if exception.response.status_code == 429: # type: ignore
return True
except Exception:
pass
return False return False

Loading…
Cancel
Save