🐛 fix(chat.py): add try-except block to handle exceptions in init_build function

The try-except block was added to handle exceptions that may occur in the init_build function. If an exception occurs, it is logged and an HTTPException with a status code of 500 is returned. This ensures that the server does not crash and provides a more informative error message to the client.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-13 20:32:05 -03:00
commit 8aac63b830

View file

@ -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)