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
|
|
@ -704,7 +704,10 @@ async def get_puzzle_of_period(
|
|||
try:
|
||||
result = await stats_service.get_puzzle_of_period(token, since, until, max)
|
||||
if not result.success:
|
||||
# Реальная ошибка при обращении к Lichess — не маскируем её под "0 пазлов"
|
||||
if result.auth_failed:
|
||||
# Токен отклонён Lichess (401/403) — permanent, ретраить бессмысленно
|
||||
raise HTTPException(status_code=401, detail=result.message)
|
||||
# Прочая (транзитная) ошибка при обращении к Lichess — не маскируем её под "0 пазлов"
|
||||
raise HTTPException(status_code=502, detail=result.message)
|
||||
return result
|
||||
except HTTPException:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue