From affba8bf66013bf2e9250f6332b9992dbdc7a873 Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Fri, 7 Oct 2022 13:13:56 +0530 Subject: [PATCH] Adds meaningful response for API caller --- pages/api/schedules/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.ts index e1b8d79350..3b8abc776f 100644 --- a/pages/api/schedules/index.ts +++ b/pages/api/schedules/index.ts @@ -15,7 +15,12 @@ async function createOrlistAllSchedules( { method, body, userId, isAdmin, prisma }: NextApiRequest, res: NextApiResponse ) { - const safe = schemaScheduleBodyParams.safeParse(safeParseJSON(body)); + body = safeParseJSON(body); + if (!body.success) { + res.status(400).json({ message: body.message }); + } + + const safe = schemaScheduleBodyParams.safeParse(body); if (!safe.success) { res.status(400).json({ message: "Bad request" });