{"record":{"id":"0de0ca1aaeaeec47","repo":"lyswhut/lx-music-desktop","slug":"error-0de0ca","errorCode":null,"errorMessage":"获取评论失败","messagePattern":"获取评论失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/utils/musicSdk/kw/comment.js","lineNumber":16,"sourceCode":"import { httpFetch } from '../../request'\nimport { dateFormat2 } from '../../index'\n\nexport default {\n  _requestObj: null,\n  _requestObj2: null,\n  async getComment({ songmid }, page = 1, limit = 20) {\n    if (this._requestObj) this._requestObj.cancelHttp()\n\n    const _requestObj = httpFetch(`http://ncomment.kuwo.cn/com.s?f=web&type=get_comment&aapiver=1&prod=kwplayer_ar_10.5.2.0&digest=15&sid=${songmid}&start=${limit * (page - 1)}&msgflag=1&count=${limit}&newver=3&uid=0`, {\n      headers: {\n        'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9;)',\n      },\n    })\n    const { body, statusCode } = await _requestObj.promise\n    if (statusCode != 200 || body.code != '200') throw new Error('获取评论失败')\n    // console.log(body)\n\n    const total = body.comments_counts\n    return {\n      source: 'kw',\n      comments: this.filterComment(body.comments),\n      total,\n      page,\n      limit,\n      maxPage: Math.ceil(total / limit) || 1,\n    }\n  },\n  async getHotComment({ songmid }, page = 1, limit = 100) {\n    if (this._requestObj2) this._requestObj2.cancelHttp()\n\n    const _requestObj2 = httpFetch(`http://ncomment.kuwo.cn/com.s?f=web&type=get_rec_comment&aapiver=1&prod=kwplayer_ar_10.5.2.0&digest=15&sid=${songmid}&start=${limit * (page - 1)}&msgflag=1&count=${limit}&newver=3&uid=0`, {\n      headers: {\n        'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9;)',","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/lyswhut/lx-music-desktop/blob/9c364b482e5621a1d38b50e8610d2fb974457e6e/src/renderer/utils/musicSdk/kw/comment.js#L1-L34","documentation":"Thrown by Kuwo's getComment when the regular comment API at http://ncomment.kuwo.cn/com.s (type=get_comment) returns a non-200 HTTP status or a body whose code field is not the string '200'. The loose equality (!=) means a numeric 200 also passes, so only truly non-200 codes or missing/mismatched body.code trigger it. This is the SDK's single guard: it cannot distinguish a network failure from an API rejection or an empty/HTML body.","triggerScenarios":"Calling getComment({ songmid }, page, limit) where songmid is invalid or the Kuwo comment endpoint is rate-limited/blocked. The HTTP scheme is plain http (not https), so corporate proxies, HTTPS-only environments, or DNS hijacking can return non-200 or HTML that fails JSON parsing (body becomes a string, body.code is undefined). Also fires when Kuwo changes its response contract (body.code format).","commonSituations":"The song has no comments on Kuwo (body.code may be a non-200 error code). ISP or GFW interference with the Kuwo domain. A stale songmid from cache. The app running behind a proxy that upgrades http to https and breaks the endpoint.","solutions":["Log statusCode and body before the throw to identify whether the failure is transport-level (non-200) or API-level (body.code mismatch).","Verify the songmid is a valid Kuwo music ID before calling getComment.","If the app runs in an HTTPS-enforcing environment, switch the URL from http:// to https:// and test.","Retry once with backoff since transient rate-limiting from Kuwo is common.","Check whether Kuwo changed the body.code contract by hitting the URL directly in a browser or curl."],"exampleFix":"// before\nconst { body, statusCode } = await _requestObj.promise\nif (statusCode != 200 || body.code != '200') throw new Error('获取评论失败')\n\n// after\nconst { body, statusCode } = await _requestObj.promise\nif (statusCode != 200 || !body || body.code != '200') {\n  console.warn('kw getComment failed', { statusCode, code: body?.code })\n  throw new Error('获取评论失败')\n}","handlingStrategy":"try-catch","validationCode":"function isValidKwCommentParams(songmid, page, limit) {\n  return typeof songmid === 'string' && songmid.length > 0 && page >= 1 && limit >= 1 && limit <= 100\n}","typeGuard":"function isKwCommentResponse(body) {\n  return body != null && typeof body === 'object' && typeof body.code !== 'undefined'\n}","tryCatchPattern":"try {\n  const result = await kwComment.getComment({ songmid }, page, limit)\n} catch (err) {\n  if (err.message === '获取评论失败') {\n    console.warn('Kuwo comments unavailable for', songmid)\n    return { source: 'kw', comments: [], total: 0, page, limit, maxPage: 1 }\n  }\n  throw err\n}","preventionTips":["Validate songmid is a non-empty string before calling getComment.","Distinguish transport failures (non-200) from API failures (body.code) by logging both.","Return an empty result set rather than propagating the error when the song simply has no comments.","Be aware the URL uses plain HTTP — test in your network environment."],"tags":["kuwo","comments","network","api-contract","http"],"backgroundTag":null,"analyzedSha":"9c364b482e5621a1d38b50e8610d2fb974457e6e","analyzedAt":"2026-08-12T15:14:48.244Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}