From 4b2cb71bed15e382ea2dfe68f46025072915b811 Mon Sep 17 00:00:00 2001 From: EthanThatOneKid <31261035+EthanThatOneKid@users.noreply.github.com> Date: Sat, 3 Aug 2024 23:17:33 -0700 Subject: [PATCH] Update app.ts --- lib/api/discord/app.ts | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/api/discord/app.ts b/lib/api/discord/app.ts index 024f0a7..e7cc25f 100644 --- a/lib/api/discord/app.ts +++ b/lib/api/discord/app.ts @@ -96,17 +96,28 @@ export function makeDiscordAppHandler( }; } - const unregisterResponse = await leaderboardClient.unregister( - interaction.user!.id, - ); - return { - type: InteractionResponseType.ChannelMessageWithSource, - data: { - content: `Your Leetcode username was ${ - unregisterResponse.ok ? "unregistered" : "not unregistered" - }.`, - }, - }; + try { + const unregisterResponse = await leaderboardClient.unregister( + interaction.user!.id, + ); + + return { + type: InteractionResponseType.ChannelMessageWithSource, + data: { + content: `Your Leetcode username was ${ + unregisterResponse.ok ? "unregistered" : "not unregistered" + }.`, + }, + }; + } catch (error) { + return { + type: InteractionResponseType.ChannelMessageWithSource, + data: { + content: `Error: ${error.message}`, + flags: MessageFlags.Ephemeral, + }, + }; + } }, async sync(interaction) { const syncResponse = await leaderboardClient.sync(