{"record":{"id":"ab33c881ce147cd2","repo":"lyswhut/lx-music-desktop","slug":"error-ab33c8","errorCode":null,"errorMessage":"获取热门评论失败","messagePattern":"获取热门评论失败","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/utils/musicSdk/mg/comment.js","lineNumber":53,"sourceCode":"  async getHotComment(musicInfo, page = 1, limit = 20) {\n    if (this._requestObj2) this._requestObj2.cancelHttp()\n\n    if (!musicInfo.songId) {\n      let id = await getSongId(musicInfo)\n      if (!id) throw new Error('获取评论失败')\n      musicInfo.songId = id\n    }\n\n    // const _requestObj2 = httpFetch(`https://music.migu.cn/v3/api/comment/listTopComments?targetId=${musicInfo.songId}&pageSize=${limit}&pageNo=${page}`, {\n    const _requestObj2 = httpFetch(`https://app.c.nf.migu.cn/MIGUM3.0/user/comment/stack/v1.0?pageSize=${limit}&queryType=2&resourceId=${musicInfo.songId}&resourceType=2&hotCommentStart=${(page - 1) * limit}`, {\n      headers: {\n        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',\n        // Referer: 'https://music.migu.cn',\n      },\n    })\n    const { body, statusCode } = await _requestObj2.promise\n    // console.log(body)\n    if (statusCode != 200 || body.code !== '000000') throw new Error('获取热门评论失败')\n    const total = parseInt(body.data.cfgHotCount)\n    return { source: 'mg', comments: this.filterComment(body.data.hotComments), total, page, limit, maxPage: Math.ceil(total / limit) || 1 }\n  },\n  async getReplyComment(musicInfo, replyId, page = 1, limit = 10) {\n    if (this._requestObj2) this._requestObj2.cancelHttp()\n\n    // const _requestObj2 = httpFetch(`https://music.migu.cn/v3/api/comment/listCommentsById?commentId=${replyId}&pageSize=${limit}&pageNo=${page}`, {\n    const _requestObj2 = httpFetch(`https://app.c.nf.migu.cn/MIGUM3.0/user/comment/stack/${replyId}/v1.0?pageSize=${limit}&queryType=2&resourceId=${musicInfo.songId}&resourceType=2&start=${(page - 1) * limit}`, {\n      headers: {\n        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1',\n      },\n    })\n    const { body, statusCode } = await _requestObj2.promise\n    // console.log(body)\n    if (statusCode != 200 || body.code !== '000000') throw new Error('获取回复评论失败')\n    const total = parseInt(body.data.replyTotalCount)\n    return { source: 'mg', comments: this.filterComment(body.data.mainCommentItem.replyComments), total, page, limit, maxPage: Math.ceil(total / limit) || 1 }\n  },","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/lyswhut/lx-music-desktop/blob/9c364b482e5621a1d38b50e8610d2fb974457e6e/src/renderer/utils/musicSdk/mg/comment.js#L35-L71","documentation":"Thrown by Migu's getHotComment when the hot comment endpoint at https://app.c.nf.migu.cn/MIGUM3.0/user/comment/stack/v1.0 (queryType=2) returns non-200 or body.code !== '000000'. Same guard as error 45 but for hot comments. Reads body.data.cfgHotCount and body.data.hotComments. Note the message says '获取热门评论失败' (hot comment failed), distinguishing it from the regular comment failure.","triggerScenarios":"The hot comment endpoint returns an error for songs with no hot comments. Rate-limiting from Migu. Invalid resourceId. Network interference with app.c.nf.migu.cn.","commonSituations":"Low-popularity songs have no hot comments, so Migu returns a non-success code. Repeated rapid calls trigger rate-limiting. The endpoint contract changed (body.code format).","solutions":["Log body.code and statusCode to identify the failure type.","Distinguish 'no hot comments' from 'API error' — return an empty list if body.code indicates empty results.","Retry with backoff for transient failures.","Fall back to regular comments if hot comments are unavailable."],"exampleFix":"// before\nif (statusCode != 200 || body.code !== '000000') throw new Error('获取热门评论失败')\n\n// after\nif (statusCode != 200 || !body || body.code !== '000000') {\n  console.warn('mg getHotComment API failed', { statusCode, code: body?.code })\n  throw new Error('获取热门评论失败')\n}","handlingStrategy":"try-catch","validationCode":"function isValidMiguSongId(songId) {\n  return typeof songId === 'string' && songId.length > 0\n}","typeGuard":"function isMiguHotCommentResponse(body) {\n  return body != null && typeof body === 'object' && body.code === '000000' && body.data != null\n}","tryCatchPattern":"try {\n  const result = await mgComment.getHotComment(musicInfo, page, limit)\n} catch (err) {\n  if (err.message === '获取热门评论失败') {\n    console.warn('Migu hot comments API failed for', musicInfo.songId)\n    return { source: 'mg', comments: [], total: 0, page, limit, maxPage: 1 }\n  }\n  throw err\n}","preventionTips":["Treat 'no hot comments' as an empty result, not an error.","Log body.code to distinguish empty results from API errors.","Retry with backoff for transient rate-limiting.","Fall back to regular comments if hot comments are unavailable."],"tags":["migu","hot-comments","network","api-contract","https"],"backgroundTag":null,"analyzedSha":"9c364b482e5621a1d38b50e8610d2fb974457e6e","analyzedAt":"2026-08-12T15:14:48.244Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}