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 math
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 requests
@ -18,9 +18,15 @@ logger = logging.getLogger(__name__)
def retry_if_ratelimit(retry_base: RetryCallState) -> bool:
"""Return whether to retry if ratelimited."""
if isinstance(retry_base.outcome.exception(), requests.exceptions.HTTPError):
if retry_base.outcome.exception().response.status_code == 429: # type: ignore
return True
try:
if isinstance(retry_base.outcome.exception(), requests.exceptions.HTTPError):
exception = cast(
requests.exceptions.HTTPError, retry_base.outcome.exception()
)
if exception.response.status_code == 429: # type: ignore
return True
except Exception:
pass
return False

Loading…
Cancel
Save