lyswhut/lx-music-desktop · error · Error

获取热门评论失败

Error message

获取热门评论失败

What it means

Thrown by Netease's getHotComment when the hot comment endpoint at https://music.163.com/weapi/v1/resource/hotcomments/{id} returns non-200 or body.code !== 200. Uses weapi encryption. Notably, page is decremented by 1 before use (page = page - 1), and beforeTime is set to Date.now() (requesting hot comments before 'now', which is the same every call). Reads body.total and body.hotComments. The id is constructed as 'R_SO_4_' + songmid.

Source

Thrown at src/renderer/utils/musicSdk/wy/comment.js:171

    const id = 'R_SO_4_' + songmid
    page = page - 1

    const _requestObj2 = httpFetch(`https://music.163.com/weapi/v1/resource/hotcomments/${id}`, {
      method: 'post',
      headers: {
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
        origin: 'https://music.163.com',
        Refere: 'http://music.163.com/',
      },
      form: weapi({
        rid: id,
        limit,
        offset: limit * page,
        beforeTime: Date.now().toString(),
      }),
    })
    const { body, statusCode } = await _requestObj2.promise
    if (statusCode != 200 || body.code !== 200) throw new Error('获取热门评论失败')
    const total = body.total ?? 0
    return { source: 'wy', comments: this.filterComment(body.hotComments), total, page, limit, maxPage: Math.ceil(total / limit) || 1 }
  },
  filterComment(rawList) {
    return rawList.map(item => {
      let data = {
        id: item.commentId,
        text: item.content ? applyEmoji(item.content) : '',
        time: item.time ? item.time : '',
        timeStr: item.time ? dateFormat2(item.time) : '',
        location: item.ipLocation?.location,
        userName: item.user.nickname,
        avatar: item.user.avatarUrl,
        userId: item.user.userId,
        likedCount: item.likedCount,
        reply: [],
      }

View on GitHub (pinned to 9c364b482e)

Solutions

  1. Log body.code and statusCode to diagnose encryption vs. rate-limiting.
  2. Guard body.hotComments before passing to filterComment (it may be undefined when there are no hot comments).
  3. Verify the weapi encryption is current.
  4. Use a CN proxy if running from outside China.
  5. Retry with backoff for transient failures.

Example fix

// before
if (statusCode != 200 || body.code !== 200) throw new Error('获取热门评论失败')
const total = body.total ?? 0
return { source: 'wy', comments: this.filterComment(body.hotComments), total, page, limit, maxPage: Math.ceil(total / limit) || 1 }

// after
if (statusCode != 200 || !body || body.code !== 200) {
  console.warn('wy getHotComment failed', { statusCode, code: body?.code })
  throw new Error('获取热门评论失败')
}
const total = body.total ?? 0
return { source: 'wy', comments: this.filterComment(body.hotComments || []), total, page, limit, maxPage: Math.ceil(total / limit) || 1 }
Defensive patterns

Strategy: try-catch

Validate before calling

function hasWySongmid({ songmid }) {
  return typeof songmid === 'string' && songmid.length > 0
}

Type guard

function isWyHotCommentResponse(body) {
  return body != null && typeof body === 'object' && body.code === 200 && Array.isArray(body.hotComments)
}

Try / catch

try {
  const result = await wyComment.getHotComment({ songmid }, page, limit)
} catch (err) {
  if (err.message === '获取热门评论失败') {
    console.warn('Netease hot comments unavailable for', songmid)
    return { source: 'wy', comments: [], total: 0, page, limit, maxPage: 1 }
  }
  throw err
}

Prevention

When it happens

Trigger: The weapi encryption is broken. The song has no hot comments (body.code may still be 200 but body.hotComments is undefined, causing a downstream crash in filterComment). Rate-limiting or IP-banning. The songmid is invalid so 'R_SO_4_' + songmid is a non-existent thread.

Common situations: Same weapi key rotation issue as error 53. Non-CN IP blocking. beforeTime set to current time means it always requests the same window — if the song has no hot comments in that window, the result is always empty. body.total ?? 0 handles missing total, but body.hotComments undefined would crash filterComment.

Related errors


AI-assisted analysis of lyswhut/lx-music-desktop@9c364b482e (2026-08-12). Data as JSON: /api/errors/0a5dfb989df57dea. Report an issue: GitHub.