{"record":{"id":"19f706b0b3e5067c","repo":"lyswhut/lx-music-desktop","slug":"error-19f706","errorCode":null,"errorMessage":"获取热搜词失败","messagePattern":"获取热搜词失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/utils/musicSdk/bd/hotSearch.js","lineNumber":16,"sourceCode":"import { httpFetch } from '../../request'\n\nexport default {\n  _requestObj: null,\n  async getList(retryNum = 0) {\n    if (this._requestObj) this._requestObj.cancelHttp()\n    if (retryNum > 2) return Promise.reject(new Error('try max num'))\n\n    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', {\n      method: 'get',\n      headers: {\n        'User-Agent': 'android_7.0.2.0;baiduyinyue',\n      },\n    })\n    const { body, statusCode } = await _requestObj.promise\n    if (statusCode != 200 || body.error_code !== 22000) throw new Error('获取热搜词失败')\n    // console.log(body, statusCode)\n    return { source: 'bd', list: this.filterList(body.result) }\n  },\n  filterList(rawList) {\n    return rawList.map(item => item.word)\n  },\n}\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/lyswhut/lx-music-desktop/blob/9c364b482e5621a1d38b50e8610d2fb974457e6e/src/renderer/utils/musicSdk/bd/hotSearch.js#L1-L24","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n    if (statusCode != 200 || body.error_code !== 22000) throw new Error('获取热搜词失败')\n\n// after - include status/code for diagnostics, keep bounded retry\n    if (statusCode != 200 || body.error_code !== 22000) {\n      throw new Error(`获取热搜词失败 (status=${statusCode}, error_code=${body?.error_code})`)\n    }","handlingStrategy":"retry","validationCode":"// pre-flight reachability check (best-effort) before calling getList\nasync function bdReachable() {\n  try {\n    const { statusCode } = await httpFetch('http://musicapi.qianqian.com/', { method: 'head', timeout: 3000 }).promise\n    return statusCode >= 200 && statusCode < 500\n  } catch { return false }\n}","typeGuard":"const isBdSuccessBody = (body) =>\n  body != null && typeof body === 'object' && body.error_code === 22000","tryCatchPattern":"// UI layer: bounded retry + graceful degrade\nasync function loadBdHotSearch() {\n  for (let n = 0; n <= 2; n++) {\n    try { return await bdHotSearch.getList(n) }\n    catch (e) { if (n === 2) return { source: 'bd', list: [], error: e.message } }\n  }\n}","preventionTips":["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."],"tags":["network","baidu","hot-search","third-party-api","retry"],"backgroundTag":null,"analyzedSha":"9c364b482e5621a1d38b50e8610d2fb974457e6e","analyzedAt":"2026-08-12T15:14:48.244Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}