Skip to content

Commit 695206e

Browse files
committed
refactor: Updated superstarify.py to use the shared retry helper from retry.py #53
1 parent 3642840 commit 695206e

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

bot/exts/moderation/infraction/superstarify.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from discord import Embed, Member
88
from discord.ext.commands import Cog, Context, command, has_any_role
99
from discord.utils import escape_markdown
10-
from pydis_core.site_api import ResponseCodeError
1110
from pydis_core.utils.members import get_or_fetch_member
1211

1312
from bot import constants
@@ -20,6 +19,7 @@
2019
from bot.log import get_logger
2120
from bot.utils import time
2221
from bot.utils.messages import format_user
22+
from bot.utils.retry import is_retryable_api_error
2323

2424
log = get_logger(__name__)
2525
NICKNAME_POLICY_URL = "https://pythondiscord.com/pages/rules/#nickname-policy"
@@ -245,18 +245,11 @@ async def _fetch_with_retries(self,
245245
try:
246246
return await self.bot.api_client.get("bot/infractions", params=params)
247247
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):
249249
raise
250250
await asyncio.sleep(URLs.connect_initial_backoff * (2 ** (attempt - 1)))
251251
return None
252252

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-
260253
async def setup(bot: Bot) -> None:
261254
"""Load the Superstarify cog."""
262255
await bot.add_cog(Superstarify(bot))

0 commit comments

Comments
 (0)