refactor: use try block for error handling and session rollback
All checks were successful
Component testing / Hub testing (push) Successful in 23s
Component testing / Store testing (push) Successful in 30s
Component testing / Integration smoke testing (push) Successful in 2m28s

This commit was merged in pull request #34.
This commit is contained in:
ІМ-24 Владислав Коваленко
2026-03-26 13:38:04 +00:00
parent 0d364ddf61
commit d073243c67

View File

@@ -60,6 +60,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: int):
# receive forever
while True:
data = await websocket.receive_text()
try:
if (data):
ws_data = WebSocketData.model_validate(json.loads(data))
session = SessionLocal()
@@ -70,9 +71,12 @@ async def websocket_endpoint(websocket: WebSocket, user_id: int):
).returning(processed_agent_data)
res = session.execute(update_query).fetchone()
if (not res):
print("Websocket update fail")
session.rollback()
raise Exception("Error while websocket PUT")
session.commit()
finally:
session.close()
except WebSocketDisconnect:
subscriptions.remove(websocket)