Skip to content

Commit

Permalink
better handle error response
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhouweling committed Oct 19, 2024
1 parent b7006c7 commit 6f51503
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/commands/stats/stats.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ export class StatsCommand extends BaseCommand {
const channel = interaction.options.get("channel", true);
const queue = interaction.options.get("queue", true);
const ephemeral = interaction.options.getBoolean("debug") ?? false;
let deferred = false;

try {
console.log(`StatsCommand execute from ${interaction.user.globalName ?? interaction.user.username}`);
const channelValue = Preconditions.checkExists(channel.channel);
const queueValue = queue.value as number;

await interaction.deferReply({ ephemeral });
deferred = true;

const queueData = await this.services.discordService.getTeamsFromQueue(
Preconditions.checkExists(channel.channel),
Expand All @@ -51,9 +53,16 @@ export class StatsCommand extends BaseCommand {
embeds: [await this.createEmbed(queueData, queueValue, series)],
});
} catch (error) {
await interaction.editReply({
const reply = {
content: `Failed to fetch (Channel: <#${channel.channel?.id ?? "unknown"}>, queue: ${queue.value?.toString() ?? "unknown"}): ${error instanceof Error ? error.message : "unknown"}`,
});
};
if (deferred) {
await interaction.editReply(reply);
} else {
await interaction.reply({ ...reply, ephemeral: true });
}

console.error(error);
}
}

Expand Down

0 comments on commit 6f51503

Please sign in to comment.