Skip to content

Commit 1495175

Browse files
committed
minor exception handling changes for websocket conn in UI
Signed-off-by: Krishna Murti <krishna.murti@intel.com>
1 parent ed5ebb2 commit 1495175

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

metro-ai-suite/smart-traffic-intersection-agent/src/ui/data_loader.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ async def fetch_intersection_data(api_url: str = Config.get_api_url()) -> None:
3232
None. Puts MonitoringData objects into the UI update queue.
3333
"""
3434
try:
35+
logger.info(f"Connecting to WebSocket API at {api_url}")
3536
async for websocket in websocket_connect(api_url, max_size=100_000_000):
36-
try:
37-
async for message in websocket:
38-
raw_data: dict = json.loads(message)
39-
traffic_data: Optional[MonitoringData] = await parse_api_response(raw_data)
40-
# Put data into the queue for the UI to consume
41-
await ui_update_queue.put(traffic_data)
42-
except WebsocketsConnectionClosed as e:
43-
logger.warning(f"WebSocket connection closed by server: {str(e)}")
44-
await asyncio.sleep(3)
45-
except WebSocketException as e:
46-
logger.error(f"WebSocket error: {str(e)}")
47-
await asyncio.sleep(3)
48-
37+
async for message in websocket:
38+
raw_data: dict = json.loads(message)
39+
traffic_data: Optional[MonitoringData] = await parse_api_response(raw_data)
40+
# Put data into the queue for the UI to consume
41+
await ui_update_queue.put(traffic_data)
42+
except WebsocketsConnectionClosed as e:
43+
logger.warning(f"WebSocket connection closed by server: {str(e)}")
44+
await asyncio.sleep(3)
45+
except WebSocketException as e:
46+
logger.error(f"WebSocket error: {str(e)}")
47+
await asyncio.sleep(3)
4948
except json.JSONDecodeError as e:
5049
logger.error("Received invalid JSON data from WebSocket")
5150
raise e
5251
except Exception as e:
5352
logger.error(f"Error Connecting to WebSocket: {str(e)}.")
53+
await asyncio.sleep(3)
5454

5555
async def update_components(debug_mode=False):
5656
"""

0 commit comments

Comments
 (0)