utility.linvite: better error handling

This commit is contained in:
Cynthia Foxwell 2023-01-26 23:02:24 -07:00
parent db56f114ac
commit 5a5c38e6d5

View file

@ -59,7 +59,12 @@ const CUSTOM_EMOTE_REGEX = /<(?:\u200b|&)?(a)?:(\w+):(\d+)>/;
const sharp = require("sharp"); const sharp = require("sharp");
const {hastebin, lookupUser, formatTime} = require("../lib/utils.js"); const {
hastebin,
lookupUser,
formatTime,
safeString,
} = require("../lib/utils.js");
const {getNamesFromString} = require("../lib/unicode.js"); const {getNamesFromString} = require("../lib/unicode.js");
const avatar = new Command("avatar"); const avatar = new Command("avatar");
@ -278,9 +283,25 @@ lookupinvite.callback = async function (msg, line) {
line = line.replace(/(https?:\/\/)?discord\.gg\//, ""); line = line.replace(/(https?:\/\/)?discord\.gg\//, "");
const invite = await hf.bot.requestHandler.request("GET", let bail = false;
`/invites/${line}?with_counts=1`, let error;
); let invite;
try {
invite = await hf.bot.requestHandler.request(
"GET",
`/invites/${line}?with_counts=1`
);
} catch (err) {
bail = true;
error = err;
}
if (bail && error) {
if (error.message.includes("Unknown Invite")) {
return "Invite provided is not valid.";
} else {
return `:warning: Got error \`${safeString(error)}\``;
}
}
if (!invite) return ":warning: No data returned."; if (!invite) return ":warning: No data returned.";
if (invite.message) { if (invite.message) {