|
7 | 7 | from discord import Embed, Member |
8 | 8 | from discord.ext.commands import Cog, Context, command, has_any_role |
9 | 9 | from discord.utils import escape_markdown |
10 | | -from pydis_core.site_api import ResponseCodeError |
11 | 10 | from pydis_core.utils.members import get_or_fetch_member |
12 | 11 |
|
13 | 12 | from bot import constants |
|
20 | 19 | from bot.log import get_logger |
21 | 20 | from bot.utils import time |
22 | 21 | from bot.utils.messages import format_user |
| 22 | +from bot.utils.retry import is_retryable_api_error |
23 | 23 |
|
24 | 24 | log = get_logger(__name__) |
25 | 25 | NICKNAME_POLICY_URL = "https://pythondiscord.com/pages/rules/#nickname-policy" |
@@ -245,18 +245,11 @@ async def _fetch_with_retries(self, |
245 | 245 | try: |
246 | 246 | return await self.bot.api_client.get("bot/infractions", params=params) |
247 | 247 | except Exception as e: |
248 | | - if attempt == retries - 1 or not self._check_error_is_retriable(e): |
| 248 | + if attempt == retries - 1 or not is_retryable_api_error(e): |
249 | 249 | raise |
250 | 250 | await asyncio.sleep(URLs.connect_initial_backoff * (2 ** (attempt - 1))) |
251 | 251 | return None |
252 | 252 |
|
253 | | - async def _check_error_is_retriable(self, error: Exception) -> bool: |
254 | | - """Return whether loading filter lists failed due to some temporary error, thus retrying could help.""" |
255 | | - if isinstance(error, ResponseCodeError): |
256 | | - return error.status in (408, 429) or error.status >= 500 |
257 | | - |
258 | | - return isinstance(error, (TimeoutError, OSError)) |
259 | | - |
260 | 253 | async def setup(bot: Bot) -> None: |
261 | 254 | """Load the Superstarify cog.""" |
262 | 255 | await bot.add_cog(Superstarify(bot)) |
0 commit comments