From f2e6ec99848baa97885c6d496a14674a8b7bf97b Mon Sep 17 00:00:00 2001 From: Laurel Orr <57237365+lorr1@users.noreply.github.com> Date: Sun, 9 Apr 2023 00:35:26 -0700 Subject: [PATCH] chore: try catch around retry error (#77) --- manifest/clients/client.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/manifest/clients/client.py b/manifest/clients/client.py index 932474b..64c136b 100644 --- a/manifest/clients/client.py +++ b/manifest/clients/client.py @@ -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