{"record":{"id":"5f81d5a70fd7fba6","repo":"lyswhut/lx-music-desktop","slug":"error-5f81d5","errorCode":null,"errorMessage":"获取评论失败","messagePattern":"获取评论失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/utils/musicSdk/kg/comment.js","lineNumber":25,"sourceCode":"  _requestObj: null,\n  _requestObj2: null,\n  async getComment({ hash }, page = 1, limit = 20) {\n    if (this._requestObj) this._requestObj.cancelHttp()\n\n    // const res_id = (await getMusicInfoRaw(hash)).classification?.[0]?.res_id\n    // if (!res_id) throw new Error('获取评论失败')\n\n    let timestamp = Date.now()\n    const params = `dfid=0&mid=16249512204336365674023395779019&clienttime=${timestamp}&uuid=0&extdata=${hash}&appid=1005&code=fc4be23b4e972707f36b8a828a93ba8a&schash=${hash}&clientver=11409&p=${page}&clienttoken=&pagesize=${limit}&ver=10&kugouid=0`\n    // const params = `appid=1005&clienttime=${timestamp}&clienttoken=0&clientver=11409&code=fc4be23b4e972707f36b8a828a93ba8a&dfid=0&extdata=${hash}&kugouid=0&mid=16249512204336365674023395779019&mixsongid=${res_id}&p=${page}&pagesize=${limit}&uuid=0&ver=10`\n    const _requestObj = httpFetch(`http://m.comment.service.kugou.com/r/v1/rank/newest?${params}&signature=${signatureParams(params)}`, {\n      headers: {\n        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.24',\n      },\n    })\n    const { body, statusCode } = await _requestObj.promise\n    // console.log(body)\n    if (statusCode != 200 || body.err_code !== 0) throw new Error('获取评论失败')\n    const total = body.count ?? 0\n    return { source: 'kg', comments: this.filterComment(body.list || []), total, page, limit, maxPage: Math.ceil(total / limit) || 1 }\n  },\n  async getHotComment({ hash }, page = 1, limit = 20) {\n    // console.log(songmid)\n    if (this._requestObj2) this._requestObj2.cancelHttp()\n    let timestamp = Date.now()\n    const params = `dfid=0&mid=16249512204336365674023395779019&clienttime=${timestamp}&uuid=0&extdata=${hash}&appid=1005&code=fc4be23b4e972707f36b8a828a93ba8a&schash=${hash}&clientver=11409&p=${page}&clienttoken=&pagesize=${limit}&ver=10&kugouid=0`\n    // https://github.com/GitHub-ZC/wp_MusicApi/blob/bf9307dd138dc8ac6c4f7de29361209d4f5b665f/routes/v1/kugou/comment.js#L53\n    const _requestObj2 = httpFetch(`http://m.comment.service.kugou.com/r/v1/rank/topliked?${params}&signature=${signatureParams(params)}`, {\n      headers: {\n        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.24',\n      },\n    })\n    const { body, statusCode } = await _requestObj2.promise\n    // console.log(body)\n    if (statusCode != 200 || body.err_code !== 0) throw new Error('获取热门评论失败')\n    const total = body.count ?? 0","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/lyswhut/lx-music-desktop/blob/9c364b482e5621a1d38b50e8610d2fb974457e6e/src/renderer/utils/musicSdk/kg/comment.js#L7-L43","documentation":"Kugou (kg) newest-comment fetcher in kg/comment.js:25. It builds signed params (signatureParams) with hardcoded mid/dfid/appid/code, fetches m.comment.service.kugou.com /v1/rank/newest with an Edge Chrome UA, and requires HTTP 200 AND body.err_code === 0; otherwise throws '获取评论失败' (failed to fetch comments).","triggerScenarios":"A non-200 response, err_code != 0, an expired/invalid signature, the hardcoded UA or mid being blocked, or the comment service moving its response shape. Triggered when the user opens the comments tab for a kg song.","commonSituations":"The signature algorithm changed so signatureParams no longer validates; the static mid (16249...) or code (fc4be23b...) was revoked by Kugou; rate-limiting returns a non-zero err_code; network failure.","solutions":["Confirm signatureParams still produces a signature Kugou accepts (regenerate the algorithm if needed).","Verify the hardcoded mid/dfid/appid/code constants haven't been deprecated.","Retry with backoff for transient non-zero err_codes (e.g. rate-limit sentinels).","Catch at the UI layer and render an empty comment state with a retry affordance."],"exampleFix":"// before\n    if (statusCode != 200 || body.err_code !== 0) throw new Error('获取评论失败')\n\n// after - include status and err_code for diagnosis\n    if (statusCode != 200 || body.err_code !== 0) {\n      throw new Error(`获取评论失败 (status=${statusCode}, err_code=${body?.err_code})`)\n    }","handlingStrategy":"retry","validationCode":"// validate response shape before treating err_code as authoritative\nconst isKgCommentSuccess = (body) =>\n  body != null && typeof body === 'object' && typeof body.err_code === 'number'","typeGuard":"const isKgCommentSuccess = (body) =>\n  body != null && typeof body === 'object' && body.err_code === 0","tryCatchPattern":"async function loadKgComments(hash, page, limit) {\n  try {\n    return await kgComment.getComment({ hash }, page, limit)\n  } catch (e) {\n    // transient? retry once with backoff; otherwise degrade\n    return { source: 'kg', comments: [], total: 0, page, limit, maxPage: 1, error: e.message }\n  }\n}","preventionTips":["Keep signatureParams aligned with Kugou's current signing algorithm.","Rotate/verify the hardcoded mid, dfid, appid, and code constants if Kugou revokes them.","Distinguish rate-limit err_codes from hard failures and retry the former with backoff."],"tags":["network","kugou","comments","third-party-api","signature"],"backgroundTag":null,"analyzedSha":"9c364b482e5621a1d38b50e8610d2fb974457e6e","analyzedAt":"2026-08-12T15:14:48.244Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}