From 8aac63b8303dedeb3b44850d85546c1277272bed Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 13 Jun 2023 20:32:05 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20add=20try-except?= =?UTF-8?q?=20block=20to=20handle=20exceptions=20in=20init=5Fbuild=20funct?= =?UTF-8?q?ion=20The=20try-except=20block=20was=20added=20to=20handle=20ex?= =?UTF-8?q?ceptions=20that=20may=20occur=20in=20the=20init=5Fbuild=20funct?= =?UTF-8?q?ion.=20If=20an=20exception=20occurs,=20it=20is=20logged=20and?= =?UTF-8?q?=20an=20HTTPException=20with=20a=20status=20code=20of=20500=20i?= =?UTF-8?q?s=20returned.=20This=20ensures=20that=20the=20server=20does=20n?= =?UTF-8?q?ot=20crash=20and=20provides=20a=20more=20informative=20error=20?= =?UTF-8?q?message=20to=20the=20client.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 5a524c0b9..04b93bd9e 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -36,11 +36,15 @@ async def chat(client_id: str, websocket: WebSocket): async def init_build(graph_data: dict): """Initialize the build by storing graph data and returning a unique session ID.""" - flow_id = graph_data.get("id") + try: + flow_id = graph_data.get("id") - flow_data_store[flow_id] = graph_data + flow_data_store[flow_id] = graph_data - return InitResponse(flowId=flow_id) + return InitResponse(flowId=flow_id) + except Exception as exc: + logger.error(exc) + return HTTPException(status_code=500, detail=str(exc)) @router.get("/build/{flow_id}/status", response_model=BuiltResponse)