image: fix some error handling

This commit is contained in:
Cynthia Foxwell 2021-07-31 15:19:13 -06:00
parent 3822efc744
commit f85975d380

View file

@ -9,9 +9,16 @@ const Jimp = require("jimp");
async function createImageCallback(msg, url, callback, filename) { async function createImageCallback(msg, url, callback, filename) {
msg.channel.sendTyping(); msg.channel.sendTyping();
const img = await getImage(msg, url); let img;
if (!img) try {
img = await getImage(msg, url);
} catch (e) {
if (e == "Image not found in last 20 messages.") {
return "Image not found. Please give URL, attachment, user mention or custom emoji."; return "Image not found. Please give URL, attachment, user mention or custom emoji.";
} else {
return ":warning: An internal error occurred.";
}
}
const out = await callback(img); const out = await callback(img);