From 2a35abdce0670238d5b0d3a482ab015b10602850 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Fri, 16 Sep 2022 21:58:41 +0800 Subject: [PATCH] fix project not found --- src/commands/modrinth.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/commands/modrinth.ts b/src/commands/modrinth.ts index 603e3cc..3dbaddc 100644 --- a/src/commands/modrinth.ts +++ b/src/commands/modrinth.ts @@ -42,9 +42,23 @@ export const modrinthCommand = async ( return; } - const data = (await fetch('https://api.modrinth.com/v2/project/' + id).then( - (a) => a.json() - )) as ModrinthProject | { error: string; description: string }; + const res = await fetch('https://api.modrinth.com/v2/project/' + id); + const data = (await res.json()) as + | ModrinthProject + | { error: string; description: string }; + + if (!res.ok) { + await i.editReply({ + embeds: [ + new EmbedBuilder() + .setTitle('Error!') + .setDescription('Not found!') + .setColor(COLORS.red), + ], + }); + + return; + } if ('error' in data) { console.error(data);