Skip to content

Commit

Permalink
use Zod validation for empty body so responses share same pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
ebisbe committed Jul 7, 2024
1 parent 515910f commit b160b99
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/functions/list/__tests__/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"}',
});
});

Expand Down
5 changes: 0 additions & 5 deletions src/functions/list/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<APIGatewayProxyEventV2> = async (event) => {
if (!event.body) {
throw new HttpError(400, "Invalid request. Missing body params.");
}

const listSchema = z.object({
userId: z.string(),
name: z.string(),
Expand Down

0 comments on commit b160b99

Please sign in to comment.