mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
fix(core): resolve unhandled rejections on 403s and undefined channel guildId
This commit is contained in:
1 parent
a467611e37
commit
5714f7b2c8
5 files changed
+91
-24
No files matched your search
@@ -44,23 +44,31 @@ export class CommandLoader {
|
||||
this.commands.on("run", (data) => {
|
||||
if (!this.runnables.has(data.command.uid)) return;
|
||||
const runFc = this.runnables.get(data.command.uid);
|
||||
const isPermError = (err) => {
|
||||
return err?.code === "MISSING_PERMISSIONS" ||
|
||||
err?.code === "COMMUNICATION_DISABLED" ||
|
||||
err?.statusCode === 403;
|
||||
};
|
||||
const sendErrorReply = (id) => {
|
||||
Promise.resolve(data.message.reply("An error occurred. Error id: `#" + id + "`"))
|
||||
.catch(err => logger.warn("[CommandHandler] Failed to send error-reply; error id #" + id + ":", err?.message));
|
||||
};
|
||||
try {
|
||||
const result = runFc.call(this.context, data.message, data);
|
||||
if (result && typeof result.catch === "function") {
|
||||
result.catch(e => {
|
||||
const id = Utils.uid();
|
||||
logger.error("Error running command; error id #" + id, e);
|
||||
sendErrorReply(id);
|
||||
});
|
||||
const handleCmdError = (e) => {
|
||||
if (isPermError(e)) {
|
||||
logger.warn(`[CommandHandler] Missing permissions in channel ${data.message?.channelId ?? data.message?.channel?.id}: ${e.code ?? e.message}`);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
const id = Utils.uid();
|
||||
logger.error("Error running command; error id #" + id, e);
|
||||
sendErrorReply(id);
|
||||
};
|
||||
try {
|
||||
const result = runFc.call(this.context, data.message, data);
|
||||
if (result && typeof result.catch === "function") {
|
||||
result.catch(handleCmdError);
|
||||
}
|
||||
} catch (e) {
|
||||
handleCmdError(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user