From d267a8d436dbd8d7e8f9fc16522ae7c1aa2bd6a4 Mon Sep 17 00:00:00 2001 From: Kush Thaker Date: Tue, 23 Jul 2024 19:19:36 +0530 Subject: [PATCH] add try catch in api/add for better error handling --- apps/cf-ai-backend/src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/cf-ai-backend/src/index.ts b/apps/cf-ai-backend/src/index.ts index 675039fa..cf6507c2 100644 --- a/apps/cf-ai-backend/src/index.ts +++ b/apps/cf-ai-backend/src/index.ts @@ -69,6 +69,7 @@ app.get("/api/health", (c) => { }); app.post("/api/add", zValidator("json", vectorObj), async (c) => { + try{ const body = c.req.valid("json"); const { store } = await initQuery(c); @@ -101,6 +102,10 @@ app.post("/api/add", zValidator("json", vectorObj), async (c) => { }); return c.json({ status: "ok" }); +}catch(error){ + console.error("Error processing request:", error); + return c.json({ status: "error", message: error.message }, 500); +} }); app.post(