From 8eb6cb83c7635351eb0940308cabc0a3af5fe619 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sat, 6 Feb 2021 23:45:37 +0200 Subject: [PATCH] better error handling for matches --- pages/api/play/matches.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pages/api/play/matches.ts b/pages/api/play/matches.ts index 08bb15c2c..bdf213ab1 100644 --- a/pages/api/play/matches.ts +++ b/pages/api/play/matches.ts @@ -2,6 +2,7 @@ import { detailedMapSchema } from "lib/validators/detailedMap"; import { NextApiRequest, NextApiResponse } from "next"; import prisma from "prisma/client"; import { rate, Rating } from "ts-trueskill"; +import * as z from "zod"; const matchesHandler = async (req: NextApiRequest, res: NextApiResponse) => { switch (req.method) { @@ -171,6 +172,9 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) { // await prisma.$transaction([updateLadderMatch, ...updateWinners, ...updateLosers] as any); res.status(200).end(); } catch (e) { + if (e instanceof z.ZodError) { + return res.status(400).json(JSON.stringify(e.errors, null, 2)); + } res.status(400).json({ message: e.message }); } }