Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/data/Thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,23 @@ class Thread {
const channel = bot.getChannel(this.channel_id);
if (channel) {
console.log(`Deleting channel ${this.channel_id}`);
await channel.delete("Thread closed");
try {
await channel.delete("Thread closed");
} catch (err) {
console.error(`Failed to delete channel ${this.channel_id} while closing thread ${this.id}:`, err);

// Reset DB status
this.status = THREAD_STATUS.OPEN;
await knex("threads")
.where("id", this.id)
.update({
status: THREAD_STATUS.OPEN
});

await this.postSystemMessage(`Failed to delete the channel: ${err.message}. The thread was not closed — try closing it again.`).catch(() => {});

throw err;
}
}

await callAfterThreadCloseHooks({ threadId: this.id });
Expand Down
15 changes: 13 additions & 2 deletions src/modules/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ module.exports = ({ bot, knex, config, commands }) => {
await thread.sendSystemMessageToUser(closeMessage).catch(() => {});
}

await thread.close(false, thread.scheduled_close_silent);
try {
await thread.close(false, thread.scheduled_close_silent);
} catch (err) {
console.error(`Error closing thread ${thread.id} on schedule:`, err);
await thread.cancelScheduledClose();
continue;
}

await sendCloseNotification(thread, `Modmail thread #${thread.thread_number} with ${thread.user_name} (${thread.user_id}) was closed as scheduled by ${thread.scheduled_close_name}`);
}
Expand Down Expand Up @@ -175,7 +181,12 @@ module.exports = ({ bot, knex, config, commands }) => {
await thread.sendSystemMessageToUser(closeMessage).catch(() => {});
}

await thread.close(suppressSystemMessages, silentClose);
try {
await thread.close(suppressSystemMessages, silentClose);
} catch (err) {
console.error(`Error closing thread ${thread.id}:`, err);
return;
}

await sendCloseNotification(thread, `Modmail thread #${thread.thread_number} with ${thread.user_name} (${thread.user_id}) was closed by ${closedBy} (${msg.author.id})`);
}, {
Expand Down