lyswhut/lx-music-desktop · error · Error
获取热搜词失败
Error message
获取热搜词失败
What it means
Baidu (bd) hot-search fetcher in bd/hotSearch.js:16. After calling the Baidu Ting hot-search endpoint with a hardcoded Android UA, getList requires HTTP 200 AND body.error_code === 22000 (Baidu's success code); any other status/code throws '获取热搜词失败' (failed to fetch hot search terms). The method already supports bounded retry via retryNum (caps at >2).
Source
Thrown at src/renderer/utils/musicSdk/bd/hotSearch.js:16
import { httpFetch } from '../../request'
export default {
_requestObj: null,
async getList(retryNum = 0) {
if (this._requestObj) this._requestObj.cancelHttp()
if (retryNum > 2) return Promise.reject(new Error('try max num'))
const _requestObj = httpFetch('http://musicapi.qianqian.com/v1/restserver/ting?from=android&version=7.0.2.0&channel=ppzs&operator=0&method=baidu.ting.search.hot', {
method: 'get',
headers: {
'User-Agent': 'android_7.0.2.0;baiduyinyue',
},
})
const { body, statusCode } = await _requestObj.promise
if (statusCode != 200 || body.error_code !== 22000) throw new Error('获取热搜词失败')
// console.log(body, statusCode)
return { source: 'bd', list: this.filterList(body.result) }
},
filterList(rawList) {
return rawList.map(item => item.word)
},
}
View on GitHub (pinned to 9c364b482e)
Solutions
- Retry via the existing retryNum mechanism (call getList(retryNum+1) up to the cap of 2).
- Verify the endpoint URL and 'User-Agent: android_7.0.2.0;baiduyinyue' still match Baidu's current mobile client.
- Catch the rejection at the UI layer and degrade to an empty list with a retry button rather than surfacing the raw error.
- Confirm body.error_code === 22000 is still Baidu's success sentinel; update if they changed it.
Example fix
// before
if (statusCode != 200 || body.error_code !== 22000) throw new Error('获取热搜词失败')
// after - include status/code for diagnostics, keep bounded retry
if (statusCode != 200 || body.error_code !== 22000) {
throw new Error(`获取热搜词失败 (status=${statusCode}, error_code=${body?.error_code})`)
} Defensive patterns
Strategy: retry
Validate before calling
// pre-flight reachability check (best-effort) before calling getList
async function bdReachable() {
try {
const { statusCode } = await httpFetch('http://musicapi.qianqian.com/', { method: 'head', timeout: 3000 }).promise
return statusCode >= 200 && statusCode < 500
} catch { return false }
} Type guard
const isBdSuccessBody = (body) => body != null && typeof body === 'object' && body.error_code === 22000
Try / catch
// UI layer: bounded retry + graceful degrade
async function loadBdHotSearch() {
for (let n = 0; n <= 2; n++) {
try { return await bdHotSearch.getList(n) }
catch (e) { if (n === 2) return { source: 'bd', list: [], error: e.message } }
}
} Prevention
- Use the existing retryNum mechanism (cap 2) for transient failures.
- Periodically verify the endpoint URL and Android UA still match Baidu's mobile client.
- Degrade to an empty list with a retry button in the UI instead of surfacing the raw rejection.
When it happens
Trigger: A non-200 response, or error_code != 22000 — endpoint down, rate-limited, the hardcoded Android 7.0.2.0 UA rejected, regional blocking, or Baidu changed the response shape/code. getList is called when the user opens the bd hot-search panel.
Common situations: Network outage or DNS failure; Baidu blocking the static UA string; an API version bump that changed error_code semantics; the user is in a region where the Ting API is unreachable.
Related errors
AI-assisted analysis of lyswhut/lx-music-desktop@9c364b482e (2026-08-12).
Data as JSON: /api/errors/19f706b0b3e5067c.
Report an issue: GitHub.