Catch URL errors in resize

This commit is contained in:
Zeva Rose 2022-04-19 14:51:36 -06:00
parent 410ee3c462
commit a0bb1a6c98

View file

@ -94,9 +94,20 @@ class ImageCog(Scale):
filename = url.split("/")[-1]
data = None
try:
async with self._session.get(url) as resp:
if resp.status == 200:
resp.raise_for_status()
if resp.content_type in ["image/jpeg", "image/png"]:
data = await resp.read()
else:
await ctx.send(
"Unsupported content type. Please send a URL to a JPEG or PNG",
ephemeral=True,
)
return
except Exception:
await ctx.send("Failed to retrieve image. Please verify url", ephemeral=True)
return
size = len(data)
if size <= tgt_size: