From 8818bf6d48df8a80faae84418cf79dc3903357de Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 26 Apr 2024 00:13:12 +0100 Subject: [PATCH] fix(api): use more appropriate status code --- .../api/admin/guilds/[guild]/categories/[category]/index.js | 6 +++--- .../[guild]/categories/[category]/questions/[question].js | 2 +- src/routes/api/admin/guilds/[guild]/tags/[tag].js | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/routes/api/admin/guilds/[guild]/categories/[category]/index.js b/src/routes/api/admin/guilds/[guild]/categories/[category]/index.js index 4ed51f2..7cb8bfe 100644 --- a/src/routes/api/admin/guilds/[guild]/categories/[category]/index.js +++ b/src/routes/api/admin/guilds/[guild]/categories/[category]/index.js @@ -9,7 +9,7 @@ module.exports.delete = fastify => ({ const guild = client.guilds.cache.get(req.params.guild); const categoryId = Number(req.params.category); const original = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } }); - if (!original || original.guildId !== guild.id) return res.status(404).send(new Error('Not Found')); + if (!original || original.guildId !== guild.id) return res.status(400).send(new Error('Bad Request')); const category = await client.prisma.category.delete({ where: { id: categoryId } }); await updateStaffRoles(guild); @@ -58,7 +58,7 @@ module.exports.get = fastify => ({ where: { id: categoryId }, }); - if (!category || category.guildId !== guildId) return res.status(404).send(new Error('Not Found')); + if (!category || category.guildId !== guildId) return res.status(400).send(new Error('Bad Request')); return category; }, @@ -118,7 +118,7 @@ module.exports.patch = fastify => ({ where: { id: categoryId }, }); - if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found')); + if (!original || original.guildId !== guildId) return res.status(400).send(new Error('Bad Request')); if (data.hasOwnProperty('id')) delete data.id; if (data.hasOwnProperty('createdAt')) delete data.createdAt; diff --git a/src/routes/api/admin/guilds/[guild]/categories/[category]/questions/[question].js b/src/routes/api/admin/guilds/[guild]/categories/[category]/questions/[question].js index 6533740..20973b5 100644 --- a/src/routes/api/admin/guilds/[guild]/categories/[category]/questions/[question].js +++ b/src/routes/api/admin/guilds/[guild]/categories/[category]/questions/[question].js @@ -9,7 +9,7 @@ module.exports.delete = fastify => ({ const questionId = req.params.question; const original = questionId && await client.prisma.question.findUnique({ where: { id: questionId } }); const category = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } }); - if (original?.categoryId !== categoryId || category.guildId !== guildId) return res.status(404).send(new Error('Not Found')); + if (original?.categoryId !== categoryId || category.guildId !== guildId) return res.status(400).send(new Error('Bad Request')); const question = await client.prisma.question.delete({ where: { id: questionId } }); logAdminEvent(client, { diff --git a/src/routes/api/admin/guilds/[guild]/tags/[tag].js b/src/routes/api/admin/guilds/[guild]/tags/[tag].js index ed2b692..6225a7a 100644 --- a/src/routes/api/admin/guilds/[guild]/tags/[tag].js +++ b/src/routes/api/admin/guilds/[guild]/tags/[tag].js @@ -8,7 +8,7 @@ module.exports.delete = fastify => ({ const guildId = req.params.guild; const tagId = Number(req.params.tag); const original = tagId && await client.prisma.tag.findUnique({ where: { id: tagId } }); - if (original.guildId !== guildId) return res.status(404).send(new Error('Not Found')); + if (original.guildId !== guildId) return res.status(400).send(new Error('Bad Request')); const tag = await client.prisma.tag.delete({ where: { id: tagId } }); const cacheKey = `cache/guild-tags:${guildId}`; @@ -46,7 +46,7 @@ module.exports.get = fastify => ({ const tagId = Number(req.params.tag); const tag = await client.prisma.tag.findUnique({ where: { id: tagId } }); - if (!tag || tag.guildId !== guildId) return res.status(404).send(new Error('Not Found')); + if (!tag || tag.guildId !== guildId) return res.status(400).send(new Error('Bad Request')); return tag; }, @@ -64,7 +64,7 @@ module.exports.patch = fastify => ({ const original = req.params.tag && await client.prisma.tag.findUnique({ where: { id: tagId } }); - if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found')); + if (!original || original.guildId !== guildId) return res.status(400).send(new Error('Bad Request')); if (data.hasOwnProperty('id')) delete data.id; if (data.hasOwnProperty('createdAt')) delete data.createdAt;