From 03892fbfd177925de67652b922589985e0ad5f43 Mon Sep 17 00:00:00 2001 From: Frisk Date: Wed, 17 Nov 2021 15:34:52 +0100 Subject: [PATCH] Don't remove webhooks when random 404, only when Discord generates json calling the webhook bad --- src/discord.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/discord.py b/src/discord.py index bb4c2af..0eaeaa8 100644 --- a/src/discord.py +++ b/src/discord.py @@ -239,11 +239,20 @@ async def handle_discord_http(code: int, formatted_embed: str, result: aiohttp.C logger.error(await result.text()) return 1 elif code == 401 or code == 404: # HTTP UNAUTHORIZED AND NOT FOUND - logger.error("Webhook URL is invalid or no longer in use, please replace it with proper one.") - async with db.pool().acquire() as connection: - await connection.execute("DELETE FROM rcgcdw WHERE webhook = $1", webhook_url) - await webhook_removal_monitor(webhook_url, code) - return 1 + if result.content_type == "application/json": + error_details = await result.json() + if error_details.get("code", -1) == 10015: + logger.error("Webhook URL is invalid or no longer in use, please replace it with proper one.") + async with db.pool().acquire() as connection: + await connection.execute("DELETE FROM rcgcdw WHERE webhook = $1", webhook_url) + await webhook_removal_monitor(webhook_url, code) + return 1 + else: + await generic_msg_sender_exception_logger("Could not get a message sent to wiki with webhook URL: {}. " + "Discord's error: {}".format(webhook_url, str(error_details))) + return 3 + + elif code == 429: logger.error("We are sending too many requests to the Discord, slowing down...") return 5