From 59456f6fa2303972c0ac7de1d1a33f16df89f544 Mon Sep 17 00:00:00 2001 From: Luca Matei Pintilie Date: Wed, 31 Aug 2022 20:10:41 +0200 Subject: Try catch everything in handleCancelButton --- src/srcom/slash_commands.tsx | 52 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'src/srcom/slash_commands.tsx') diff --git a/src/srcom/slash_commands.tsx b/src/srcom/slash_commands.tsx index 69d1878..15698d5 100644 --- a/src/srcom/slash_commands.tsx +++ b/src/srcom/slash_commands.tsx @@ -437,31 +437,35 @@ export class SpeedrunCom extends ApplicationCommandsModule { i: MessageComponentInteraction, ): Promise { const task = runningTasks.get(i.customID)!; - if (!task) { - await i.send({ - content: "Sorry, but I couldn't find the running task to cancel.", - ephemeral: true, - }); - return; - } - if (task.user !== i.user.id) { - await i.send({ - content: "You are not allowed to cancel this.", - ephemeral: true, - }); - return; - } - task.signal.abort(); try { - await i.respond({ - content: "Canceled", - ephemeral: true, - }); - } catch { - await i.editResponse({ - content: "Canceled", - ephemeral: true, - }); + if (!task) { + await i.send({ + content: "Sorry, but I couldn't find the running task to cancel.", + ephemeral: true, + }); + return; + } + if (task.user !== i.user.id) { + await i.send({ + content: "You are not allowed to cancel this.", + ephemeral: true, + }); + return; + } + task.signal.abort(); + try { + await i.respond({ + content: "Canceled", + ephemeral: true, + }); + } catch { + await i.editResponse({ + content: "Canceled", + ephemeral: true, + }); + } + } catch (err) { + console.error(err); } runningTasks.delete(i.customID); } -- cgit v1.2.3