From a700ab1f71e3ceb6237cf8853b2175c64da96542 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 27 Aug 2023 19:16:30 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(endpoints.py):=20handle=20sp?= =?UTF-8?q?ecific=20exceptions=20when=20processing=20flow=20to=20provide?= =?UTF-8?q?=20more=20informative=20error=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/endpoints.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/api/v1/endpoints.py b/src/backend/langflow/api/v1/endpoints.py index 173a2c572..3d2416296 100644 --- a/src/backend/langflow/api/v1/endpoints.py +++ b/src/backend/langflow/api/v1/endpoints.py @@ -8,8 +8,8 @@ from langflow.processing.process import process_graph_cached, process_tweaks from langflow.services.database.models.user.user import User from langflow.services.utils import get_settings_manager from langflow.utils.logger import logger -from fastapi import APIRouter, Depends, HTTPException, UploadFile, Body - +from fastapi import APIRouter, Depends, HTTPException, UploadFile, Body, status +import sqlalchemy as sa from langflow.interface.custom.custom_component import CustomComponent @@ -116,6 +116,18 @@ async def process_flow( graph_data, inputs, clear_cache, session_id ) return ProcessResponse(result=response, session_id=session_id) + except sa.exc.StatementError as exc: + # StatementError('(builtins.ValueError) badly formed hexadecimal UUID string') + if "badly formed hexadecimal UUID string" in str(exc): + # This means the Flow ID is not a valid UUID which means it can't find the flow + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) + except ValueError as exc: + if f"Flow {flow_id} not found" in str(exc): + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(exc)) + else: + raise HTTPException( + status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(exc) + ) except Exception as e: # Log stack trace logger.exception(e)