From 02b8b6efc266d0c8f845ed43b0494cbab3b22758 Mon Sep 17 00:00:00 2001 From: Karan Gauswami Date: Sun, 22 Oct 2023 20:23:37 +0530 Subject: [PATCH] aws-node-express-dynamodb-api return early in case of validation error --- aws-node-express-dynamodb-api/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws-node-express-dynamodb-api/index.js b/aws-node-express-dynamodb-api/index.js index 369c67e1d..d50eaa3fa 100644 --- a/aws-node-express-dynamodb-api/index.js +++ b/aws-node-express-dynamodb-api/index.js @@ -43,9 +43,9 @@ app.get("/users/:userId", async function (req, res) { app.post("/users", async function (req, res) { const { userId, name } = req.body; if (typeof userId !== "string") { - res.status(400).json({ error: '"userId" must be a string' }); + return res.status(400).json({ error: '"userId" must be a string' }); } else if (typeof name !== "string") { - res.status(400).json({ error: '"name" must be a string' }); + return res.status(400).json({ error: '"name" must be a string' }); } const params = {