diff --git a/backend/services/garmin.py b/backend/services/garmin.py index 74cf88b..f422ced 100644 --- a/backend/services/garmin.py +++ b/backend/services/garmin.py @@ -204,8 +204,22 @@ def _is_rate_limited(e): if response is not None and getattr(response, "status_code", None) == 429: return True - haystacks = [str(e), str(getattr(e, "doc", "") or "")] - return any("rate limit" in h.lower() for h in haystacks) + # The 429 can be buried several layers down: garth/urllib3 fold the final + # 429 into a RetryError whose message is 'too many 429 error responses' — + # no status code survives and the words "rate limit" never appear. Walk the + # cause chain and also accept the "429" marker itself. + seen = set() + cur = e + while cur is not None and id(cur) not in seen: + seen.add(id(cur)) + response = getattr(cur, "response", None) + if response is not None and getattr(response, "status_code", None) == 429: + return True + text = f"{cur} {getattr(cur, 'doc', '') or ''}" + if "429" in text or "rate limit" in text.lower(): + return True + cur = getattr(cur, "__cause__", None) or getattr(cur, "__context__", None) + return False class MFARequired(RuntimeError): diff --git a/backend/services/garmin_auth.py b/backend/services/garmin_auth.py index b91b853..91e47ec 100644 --- a/backend/services/garmin_auth.py +++ b/backend/services/garmin_auth.py @@ -121,7 +121,7 @@ def _run_login(session_id, user_id, garmin_email, password, is_cn, import_garmin if garmin_svc._is_rate_limited(e): garmin_svc._note_rate_limit(user_id) error = ( - "Garmin 返回 429 限流(登录接口)。已自动退避 6 小时," + "Garmin 返回 429 限流(登录接口)。已自动退避 24 小时," "请等待冷却窗口结束后再试——反复尝试会越撞越久。" ) else: