Catch all generic errors

This commit is contained in:
Zeva Rose 2022-04-30 19:53:20 -06:00
parent 373e95b9af
commit a9067bbdeb

View file

@ -13,7 +13,7 @@ from dis_snek.api.events.discord import (
MessageDelete,
MessageUpdate,
)
from dis_snek.client.errors import CommandCheckFailure, CommandOnCooldown
from dis_snek.client.errors import CommandCheckFailure, CommandOnCooldown, HTTPException
from dis_snek.client.utils.misc_utils import find_all
from dis_snek.models.discord.channel import DMChannel
from dis_snek.models.discord.embed import EmbedField
@ -107,7 +107,7 @@ class Jarvis(Snake):
@listen()
async def on_ready(self) -> None:
"""Lepton on_ready override."""
"""NAFF on_ready override."""
await self._sync_domains()
self._update_domains.start()
self.logger.info("Logged in as {}".format(self.user)) # noqa: T001
@ -118,10 +118,19 @@ class Jarvis(Snake):
"{}&permissions=8&scope=bot%20applications.commands".format(self.user.id)
)
async def on_error(self, source: str, error: Exception, *args, **kwargs) -> None:
"""NAFF on_error override."""
if isinstance(error, HTTPException):
errors = error.search_for_message(error.errors)
out = f"HTTPException: {error.status}|{error.response.reason}: " + "\n".join(errors)
self.logger.error(out, exc_info=error)
else:
self.logger.error(f"Ignoring exception in {source}", exc_info=error)
async def on_command_error(
self, ctx: Context, error: Exception, *args: list, **kwargs: dict
) -> None:
"""Lepton on_command_error override."""
"""NAFF on_command_error override."""
self.logger.debug(f"Handling error in {ctx.invoked_name}: {error}")
if isinstance(error, CommandOnCooldown):
await ctx.send(str(error), ephemeral=True)
@ -186,7 +195,7 @@ class Jarvis(Snake):
# Modlog
async def on_command(self, ctx: Context) -> None:
"""Lepton on_command override."""
"""NAFF on_command override."""
if not isinstance(ctx.channel, DMChannel) and ctx.invoked_name not in ["pw"]:
modlog = await Setting.find_one(q(guild=ctx.guild.id, setting="activitylog"))
if modlog: