From b160b994e74cfeab38ecfbd41e6ab050782d9ce7 Mon Sep 17 00:00:00 2001 From: Enric Bisbe Gil Date: Sun, 7 Jul 2024 19:02:01 +0200 Subject: [PATCH] use Zod validation for empty body so responses share same pattern --- src/functions/list/__tests__/create.test.js | 4 ++-- src/functions/list/create.ts | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/functions/list/__tests__/create.test.js b/src/functions/list/__tests__/create.test.js index 7da4f7a..5d956aa 100644 --- a/src/functions/list/__tests__/create.test.js +++ b/src/functions/list/__tests__/create.test.js @@ -13,8 +13,8 @@ describe("CREATE List", () => { expect(response).toStrictEqual({ statusCode: 400, - headers: { "Content-Type": "text/plain" }, - body: "Invalid request. Missing body params.", + headers: { "Content-Type": "application/json" }, + body: '{"issues":[{"code":"invalid_type","expected":"object","received":"null","path":[],"message":"Expected object, received null"}],"name":"ZodError"}', }); }); diff --git a/src/functions/list/create.ts b/src/functions/list/create.ts index 0e64afc..12a78f3 100644 --- a/src/functions/list/create.ts +++ b/src/functions/list/create.ts @@ -5,14 +5,9 @@ import { APIGatewayProxyEventV2, Handler } from "aws-lambda"; import { z } from "zod"; import { List } from "../../models/table"; -import { HttpError } from "../../utils/httpError"; import { ValidationError } from "../../utils/validationError"; const createListHandler: Handler = async (event) => { - if (!event.body) { - throw new HttpError(400, "Invalid request. Missing body params."); - } - const listSchema = z.object({ userId: z.string(), name: z.string(),