aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/moderation/incidents.py2
-rw-r--r--tests/bot/cogs/moderation/test_incidents.py14
2 files changed, 14 insertions, 2 deletions
diff --git a/bot/cogs/moderation/incidents.py b/bot/cogs/moderation/incidents.py
index 018538040..2d5f26f20 100644
--- a/bot/cogs/moderation/incidents.py
+++ b/bot/cogs/moderation/incidents.py
@@ -55,6 +55,8 @@ async def download_file(attachment: discord.Attachment) -> t.Optional[discord.Fi
log.debug(f"Attempting to download attachment: {attachment.filename}")
try:
return await attachment.to_file()
+ except discord.NotFound as not_found:
+ log.debug(f"Failed to download attachment: {not_found}")
except Exception:
log.exception("Failed to download attachment")
diff --git a/tests/bot/cogs/moderation/test_incidents.py b/tests/bot/cogs/moderation/test_incidents.py
index 9b6054f55..435a1cd51 100644
--- a/tests/bot/cogs/moderation/test_incidents.py
+++ b/tests/bot/cogs/moderation/test_incidents.py
@@ -81,13 +81,23 @@ class TestDownloadFile(unittest.IsolatedAsyncioTestCase):
acquired_file = await incidents.download_file(attachment)
self.assertIs(file, acquired_file)
- async def test_download_file_fail(self):
- """If `to_file` fails, function handles the exception & returns None."""
+ async def test_download_file_404(self):
+ """If `to_file` encounters a 404, function handles the exception & returns None."""
attachment = MockAttachment(to_file=AsyncMock(side_effect=mock_404))
acquired_file = await incidents.download_file(attachment)
self.assertIsNone(acquired_file)
+ async def test_download_file_fail(self):
+ """If `to_file` fails on a non-404 error, function logs the exception & returns None."""
+ arbitrary_error = discord.HTTPException(MagicMock(aiohttp.ClientResponse), "Arbitrary API error")
+ attachment = MockAttachment(to_file=AsyncMock(side_effect=arbitrary_error))
+
+ with self.assertLogs(logger=incidents.log, level=logging.ERROR):
+ acquired_file = await incidents.download_file(attachment)
+
+ self.assertIsNone(acquired_file)
+
class TestMakeEmbed(unittest.IsolatedAsyncioTestCase):
"""Collection of tests for the `make_embed` helper function."""