From c2ae3ec0e3191ffc8fde4a1fbadc1439efcb6631 Mon Sep 17 00:00:00 2001 From: Sukma Gladys Date: Wed, 14 Aug 2024 10:28:41 +0700 Subject: [PATCH] fix: revise throw error --- apps/backend/src/routes/questions/route.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/apps/backend/src/routes/questions/route.ts b/apps/backend/src/routes/questions/route.ts index ed556cf..d605c58 100644 --- a/apps/backend/src/routes/questions/route.ts +++ b/apps/backend/src/routes/questions/route.ts @@ -147,10 +147,7 @@ const questionsRoute = new Hono() ) ); - if (!queryResult.length) - throw new HTTPException(404, { - message: "The question does not exists", - }); + if (!queryResult[0]) throw notFound(); const questionData = { ...queryResult[0], @@ -256,10 +253,7 @@ const questionsRoute = new Hono() ) ); - if (!question[0]) - throw new HTTPException(404, { - message: "The question is not found", - }); + if (!question[0]) throw notFound(); if (skipTrash) { await db.delete(questions).where(eq(questions.id, questionId)); @@ -291,7 +285,7 @@ const questionsRoute = new Hono() await db.select().from(questions).where(eq(questions.id, questionId)) )[0]; - if (!question) return c.notFound(); + if (!question) throw notFound(); if (!question.deletedAt) { throw new HTTPException(400, {