Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bot/exts/backend/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@ async def handle_api_error(ctx: Context, e: ResponseCodeError) -> None:
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:
Expand Down
47 changes: 30 additions & 17 deletions bot/exts/moderation/modlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
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
Expand Down Expand Up @@ -53,24 +55,35 @@ async def upload_log(
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,
)
Comment on lines +80 to +85
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a discrepancy in the documentation of this function: https://getsentry.github.io/sentry-python/api.html?highlight=add_breadcrumb#sentry_sdk.add_breadcrumb vs https://docs.sentry.io/platforms/python/enriching-events/breadcrumbs/#manual-breadcrumbs

I don't know how to test this so let's just try and fix it if it doesn't work.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I was following the latter. I guess we can just find out.

raise

return f"{URLs.site_logs_view}/{response['id']}"

Expand Down