Handle non-existant applications more gracefully

This commit is contained in:
Rory&
2026-07-01 18:38:21 +02:00
parent e45a3cd680
commit 5f76f5f4af
@@ -98,6 +98,7 @@ router.post(
const body = req.body as EmojiCreateSchema;
const app = await Application.findOne({ where: { id: application_id } });
if (!app) throw DiscordApiErrors.UNKNOWN_APPLICATION;
if (req.user_id != app?.id && req.user_id != app?.owner_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
const id = Snowflake.generate();
@@ -148,6 +149,7 @@ router.patch(
const body = req.body as ApplicationEmojiModifySchema;
const app = await Application.findOne({ where: { id: application_id } });
if (!app) throw DiscordApiErrors.UNKNOWN_APPLICATION;
if (req.user_id != app?.id && req.user_id != app?.owner_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
if (body.name?.includes("-")) body.name = body.name?.replaceAll("-", ""); // Dashes are invalid apparently
@@ -180,6 +182,7 @@ router.delete(
const { emoji_id, application_id } = req.params as { [key: string]: string };
const app = await Application.findOne({ where: { id: application_id } });
if (!app) throw DiscordApiErrors.UNKNOWN_APPLICATION;
if (req.user_id != app?.id && req.user_id != app?.owner_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
await Emoji.delete({