Don't remove webhooks when random 404, only when Discord generates json calling the webhook bad

This commit is contained in:
Frisk 2021-11-17 15:34:52 +01:00
parent 4a272eb8c9
commit 03892fbfd1
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC

View file

@ -239,11 +239,20 @@ async def handle_discord_http(code: int, formatted_embed: str, result: aiohttp.C
logger.error(await result.text()) logger.error(await result.text())
return 1 return 1
elif code == 401 or code == 404: # HTTP UNAUTHORIZED AND NOT FOUND elif code == 401 or code == 404: # HTTP UNAUTHORIZED AND NOT FOUND
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.") logger.error("Webhook URL is invalid or no longer in use, please replace it with proper one.")
async with db.pool().acquire() as connection: async with db.pool().acquire() as connection:
await connection.execute("DELETE FROM rcgcdw WHERE webhook = $1", webhook_url) await connection.execute("DELETE FROM rcgcdw WHERE webhook = $1", webhook_url)
await webhook_removal_monitor(webhook_url, code) await webhook_removal_monitor(webhook_url, code)
return 1 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: elif code == 429:
logger.error("We are sending too many requests to the Discord, slowing down...") logger.error("We are sending too many requests to the Discord, slowing down...")
return 5 return 5