From 1407719f2fb8417d8b3a608ca29a727d7d0f27d7 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 30 Aug 2023 18:12:03 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20handle=20unautho?= =?UTF-8?q?rized=20error=20in=20chat=20websocket=20to=20return=20WS=5F1008?= =?UTF-8?q?=5FPOLICY=5FVIOLATION=20status=20code=20and=20"Unauthorized"=20?= =?UTF-8?q?reason?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index bd24806ff..eb6d13ef5 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -61,7 +61,12 @@ async def chat( await websocket.close(code=status.WS_1011_INTERNAL_ERROR, reason=str(exc)) except Exception as exc: logger.error(f"Error in chat websocket: {exc}") - await websocket.close(code=status.WS_1011_INTERNAL_ERROR, reason=str(exc)) + if "Could not validate credentials" in str(exc): + await websocket.close( + code=status.WS_1008_POLICY_VIOLATION, reason="Unauthorized" + ) + else: + await websocket.close(code=status.WS_1011_INTERNAL_ERROR, reason=str(exc)) @router.post("/build/init/{flow_id}", response_model=InitResponse, status_code=201)