Skip to content

Commit e08daa0

Browse files
committed
fix: handle player stats retrieval errors and update UI accordingly
1 parent 407ac74 commit e08daa0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/routes/index.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ async def _playtime_update(self):
475475
player_stats = await stats.get_player_stats(
476476
account.user["user"]["players"][0]["uuid"]
477477
)
478+
if player_stats is None:
479+
self._playtime_text.value = "Час на сервері: -"
480+
self._latest_online_text.value = "Останній вхід: -"
481+
await asyncio.sleep(60)
482+
continue
478483
player_stats = player_stats.get("info", {})
479484
playtime = player_stats.get("playtime", "0")
480485
last_seen = player_stats.get("last_seen", "Ніколи")

src/stats.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ async def get_player_stats(self, uuid: str):
1717
params={"player": uuid}
1818
)
1919
# Raise an error if the request was unsuccessful
20-
if response.status_code == 403:
20+
if response.status_code != 200:
2121
# rate limit exceeded
2222
return None
23-
return response.json()
23+
try:
24+
return response.json()
25+
except Exception:
26+
return None
2427

2528

2629
stats = Stats()

0 commit comments

Comments
 (0)