From d14be904adb42ce91912a409358748bf643307a2 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 12 Jun 2023 20:43:55 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20raise=20HTTPExce?= =?UTF-8?q?ption=20instead=20of=20returning=20JSONResponse=20on=20stream?= =?UTF-8?q?=5Fbuild=20error=20The=20function=20stream=5Fbuild=20was=20retu?= =?UTF-8?q?rning=20a=20JSONResponse=20with=20an=20error=20message=20when?= =?UTF-8?q?=20an=20exception=20was=20raised.=20This=20is=20not=20the=20cor?= =?UTF-8?q?rect=20way=20to=20handle=20errors=20in=20FastAPI.=20Instead,=20?= =?UTF-8?q?we=20should=20raise=20an=20HTTPException=20with=20the=20appropr?= =?UTF-8?q?iate=20status=20code=20and=20error=20message.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 5b053fee1..5ce1ff2ab 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -105,4 +105,4 @@ async def stream_build(flow_id: str): return StreamingResponse(event_stream(flow_id), media_type="text/event-stream") except Exception as exc: logger.error(exc) - return JSONResponse(content={"error": str(exc)}) + raise HTTPException(status_code=500, detail=str(exc))