Files
teamspeak-music-bot/src
jiayuLian e9995c1e30 fix(playback): back off properly when NetEase risk control answers -460
Measured directly against the sidecar on a cloud host, same song, same minute:

  GET /song/url/v1?id=1827600686&level=exhigh                → 400
      {"code":-460,"message":"检测到您的网络环境存在风险,请稍后再试"}
  GET …&cookie=<account cookie>                              → 200, 320k url

So the "无法播放(区域/版权限制)" everyone was chasing is NetEase rejecting
the host's IP, not a copyright or membership problem. It arrives as a 4xx,
which axios reports as ERR_BAD_REQUEST — indistinguishable from a malformed
request without reading the body — and that is why it looked like a dead end in
the logs.

The previous commit retried everything on a flat 250ms backoff. For -460 that
is useless: the risk window lasts a few seconds, so three re-pokes inside 750ms
all land in it and the budget is spent without ever giving the upstream time to
relax. It also spent the 120ms level-switch delay on it, but -460 ignores which
quality we ask for.

Now:

- `netease.getSongUrl` recognises 400 + `code: -460` and rethrows
  `RiskControlError` (provider.ts), so the retry layer can tell "wait this out"
  from "this track will never play".
- `resolveUrlWithRetry` waits `RISK_CONTROL_BACKOFF_MS * attempt` (800ms,
  1600ms, …) instead of 250ms, and never uses the fast level-switch delay while
  risk controlled.
- The failure log now says what actually happened
  (`hit NetEase risk control (-460) — backing off`) instead of dumping an axios
  error that reads like a broken request.

Everything else keeps the old timing: a plain thrown error still retries at
250ms, a genuine 400 (`code: 400`) is not reclassified, and a 200 with `url:null`
still falls through to the quality ladder.

11 new tests: -460 → RiskControlError, genuine 400 untouched, HTML 400
untouched, message preserved, exponential wait, no 120ms switch under risk
control, recovery stops spending, cancellation during a wait.
2026-11-08 17:53:43 +08:00
..