diff options
author | 2022-05-29 09:37:28 +0100 | |
---|---|---|
committer | 2022-05-29 09:37:28 +0100 | |
commit | c29434b964e87743869723da51a7908be7cc7156 (patch) | |
tree | 8dc57276dda947170f4e6402c4ea1f7bb9b13f3c | |
parent | Merge pull request #2182 from python-discord/clean---works-for-active-threads... (diff) | |
parent | Merge branch 'main' into Log-more-data-on-failed-clean (diff) |
Merge pull request #2180 from python-discord/Log-more-data-on-failed-clean
Log more data on failed clean
-rw-r--r-- | bot/exts/backend/error_handler.py | 7 | ||||
-rw-r--r-- | bot/exts/moderation/modlog.py | 47 |
2 files changed, 35 insertions, 19 deletions
diff --git a/bot/exts/backend/error_handler.py b/bot/exts/backend/error_handler.py index 35dddd8dc..194a4889d 100644 --- a/bot/exts/backend/error_handler.py +++ b/bot/exts/backend/error_handler.py @@ -284,8 +284,11 @@ class ErrorHandler(Cog): await ctx.send("There does not seem to be anything matching your query.") ctx.bot.stats.incr("errors.api_error_404") elif e.status == 400: - content = await e.response.json() - log.error(f"API responded with 400 for command {ctx.command}: %r.", content) + log.error( + "API responded with 400 for command %s: %r.", + ctx.command, + e.response_json or e.response_text, + ) await ctx.send("According to the API, your request is malformed.") ctx.bot.stats.incr("errors.api_error_400") elif 500 <= e.status < 600: diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py index 80f68e442..67991730e 100644 --- a/bot/exts/moderation/modlog.py +++ b/bot/exts/moderation/modlog.py @@ -6,12 +6,14 @@ from datetime import datetime, timezone from itertools import zip_longest import discord +from botcore.site_api import ResponseCodeError from dateutil.relativedelta import relativedelta from deepdiff import DeepDiff from discord import Colour, Message, Thread from discord.abc import GuildChannel from discord.ext.commands import Cog, Context from discord.utils import escape_markdown, format_dt, snowflake_time +from sentry_sdk import add_breadcrumb from bot.bot import Bot from bot.constants import Categories, Channels, Colours, Emojis, Event, Guild as GuildConstant, Icons, Roles, URLs @@ -53,24 +55,35 @@ class ModLog(Cog, name="ModLog"): if attachments is None: attachments = [] - response = await self.bot.api_client.post( - 'bot/deleted-messages', - json={ - 'actor': actor_id, - 'creation': datetime.now(timezone.utc).isoformat(), - 'deletedmessage_set': [ - { - 'id': message.id, - 'author': message.author.id, - 'channel_id': message.channel.id, - 'content': message.content.replace("\0", ""), # Null chars cause 400. - 'embeds': [embed.to_dict() for embed in message.embeds], - 'attachments': attachment, - } - for message, attachment in zip_longest(messages, attachments, fillvalue=[]) - ] + deletedmessage_set = [ + { + "id": message.id, + "author": message.author.id, + "channel_id": message.channel.id, + "content": message.content.replace("\0", ""), # Null chars cause 400. + "embeds": [embed.to_dict() for embed in message.embeds], + "attachments": attachment, } - ) + for message, attachment in zip_longest(messages, attachments, fillvalue=[]) + ] + + try: + response = await self.bot.api_client.post( + "bot/deleted-messages", + json={ + "actor": actor_id, + "creation": datetime.now(timezone.utc).isoformat(), + "deletedmessage_set": deletedmessage_set, + } + ) + except ResponseCodeError as e: + add_breadcrumb( + category="api_error", + message=str(e), + level="error", + data=deletedmessage_set, + ) + raise return f"{URLs.site_logs_view}/{response['id']}" |