stop infinite retry loop on rejected Lichess tokens
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 12s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 12s
A gamer's periodic check would get permanently stuck if their stored token was revoked/expired: our stats API collapsed both "Lichess rejected the token" (401/403, permanent) and genuine transient errors into the same 502 response, so the bot treated an invalid token exactly like a network blip — retrying the same window forever at a capped 300s backoff, never advancing the checkpoint (observed in prod: Dor1zz stuck for 100+ consecutive errors over 8+ hours, admin alerts firing every 25 failures). Preserve the distinction that already existed one layer down (lichess_client.py already tells 401/403 apart from other failures) instead of collapsing it in stats_service.py: add PuzzleOfPeriodResponse.auth_failed, have main.py return 401 specifically for that case, and have the bot raise a distinct InvalidTokenError instead of returning None. On InvalidTokenError, the bot now clears the token for that pair, notifies the user to reconnect via /addtoken, and continues tracking games normally instead of stalling forever.
This commit is contained in:
parent
8080921141
commit
619c00aa06
7 changed files with 70 additions and 16 deletions
|
|
@ -72,7 +72,8 @@ TRANSLATIONS = {
|
|||
'user_not_found': "❌ Player {username} not found on Lichess. Check the spelling of the name.",
|
||||
'lichess_temporarily_unavailable': "⚠️ Lichess is temporarily unavailable. Please try again in a minute.",
|
||||
'gamer_already_added': "ℹ️ Player {username} is already being tracked.\n\nTo add another player, use /addgamer",
|
||||
|
||||
'token_rejected_notice': "⚠️ Lichess rejected the saved token for {username} — puzzle stats have been turned off for this player, game tracking continues as normal. Use /addtoken to reconnect a fresh token if you want puzzle stats back.",
|
||||
|
||||
# Get gamers
|
||||
'no_gamers': "📭 No players in database. Use /addgamer to add.",
|
||||
'loading_ratings': "🔄 Loading player ratings...",
|
||||
|
|
@ -215,7 +216,8 @@ TRANSLATIONS = {
|
|||
'user_not_found': "❌ Игрок {username} не найден на Lichess. Проверьте правильность написания имени.",
|
||||
'lichess_temporarily_unavailable': "⚠️ Lichess временно недоступен. Попробуйте, пожалуйста, через минуту.",
|
||||
'gamer_already_added': "ℹ️ Игрок {username} уже отслеживается.\n\nДля добавления следующего игрока воспользуйтесь /addgamer",
|
||||
|
||||
'token_rejected_notice': "⚠️ Lichess отклонил сохранённый токен для {username} — статистика по пазлам для этого игрока отключена, отслеживание партий продолжается как обычно. Используйте /addtoken, чтобы подключить новый токен и вернуть статистику по пазлам.",
|
||||
|
||||
# Get gamers
|
||||
'no_gamers': "📭 Нет игроков в базе данных. Используйте /addgamer для добавления.",
|
||||
'loading_ratings': "🔄 Загрузка рейтингов игроков...",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue