Refactor exception handling and error messaging in chat module
This commit is contained in:
parent
6a25d4b761
commit
f170712864
3 changed files with 29 additions and 3 deletions
|
|
@ -301,3 +301,10 @@ def get_top_level_vertices(graph, vertices_ids):
|
|||
else:
|
||||
top_level_vertices.append(vertex_id)
|
||||
return top_level_vertices
|
||||
|
||||
|
||||
def parse_exception(exc):
|
||||
"""Parse the exception message."""
|
||||
if hasattr(exc, "body"):
|
||||
return exc.body["message"]
|
||||
return str(exc)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from langflow.api.utils import (
|
|||
format_elapsed_time,
|
||||
format_exception_message,
|
||||
get_top_level_vertices,
|
||||
parse_exception,
|
||||
)
|
||||
from langflow.api.v1.schemas import (
|
||||
InputValueRequest,
|
||||
|
|
@ -314,7 +315,10 @@ async def build_vertex_stream(
|
|||
|
||||
except Exception as exc:
|
||||
logger.exception(f"Error building vertex: {exc}")
|
||||
yield str(StreamData(event="error", data={"error": str(exc)}))
|
||||
exc_message = parse_exception(exc)
|
||||
if exc_message == "The message must be an iterator or an async iterator.":
|
||||
exc_message = "This stream has already been closed."
|
||||
yield str(StreamData(event="error", data={"error": exc_message}))
|
||||
finally:
|
||||
logger.debug("Closing stream")
|
||||
yield str(StreamData(event="close", data={"message": "Stream closed"}))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue