Catch URL errors in resize
This commit is contained in:
parent
410ee3c462
commit
a0bb1a6c98
1 changed files with 14 additions and 3 deletions
|
@ -94,9 +94,20 @@ class ImageCog(Scale):
|
||||||
filename = url.split("/")[-1]
|
filename = url.split("/")[-1]
|
||||||
|
|
||||||
data = None
|
data = None
|
||||||
async with self._session.get(url) as resp:
|
try:
|
||||||
if resp.status == 200:
|
async with self._session.get(url) as resp:
|
||||||
data = await resp.read()
|
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)
|
size = len(data)
|
||||||
if size <= tgt_size:
|
if size <= tgt_size:
|
||||||
|
|
Loading…
Add table
Reference in a new issue