🐛 fix(chat.py): raise HTTPException instead of returning JSONResponse on stream_build error

The function stream_build was returning a JSONResponse with an error message when an exception was raised. This is not the correct way to handle errors in FastAPI. Instead, we should raise an HTTPException with the appropriate status code and error message.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-12 20:43:55 -03:00
commit d14be904ad

View file

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