lyswhut/lx-music-desktop · error · Error

获取评论失败

Error message

获取评论失败

What it means

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.

Source

Thrown at src/renderer/utils/musicSdk/kw/comment.js:16

import { httpFetch } from '../../request'
import { dateFormat2 } from '../../index'

export default {
  _requestObj: null,
  _requestObj2: null,
  async getComment({ songmid }, page = 1, limit = 20) {
    if (this._requestObj) this._requestObj.cancelHttp()

    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`, {
      headers: {
        'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9;)',
      },
    })
    const { body, statusCode } = await _requestObj.promise
    if (statusCode != 200 || body.code != '200') throw new Error('获取评论失败')
    // console.log(body)

    const total = body.comments_counts
    return {
      source: 'kw',
      comments: this.filterComment(body.comments),
      total,
      page,
      limit,
      maxPage: Math.ceil(total / limit) || 1,
    }
  },
  async getHotComment({ songmid }, page = 1, limit = 100) {
    if (this._requestObj2) this._requestObj2.cancelHttp()

    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`, {
      headers: {
        'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9;)',

View on GitHub (pinned to 9c364b482e)

Solutions

  1. Log statusCode and body before the throw to identify whether the failure is transport-level (non-200) or API-level (body.code mismatch).
  2. Verify the songmid is a valid Kuwo music ID before calling getComment.
  3. If the app runs in an HTTPS-enforcing environment, switch the URL from http:// to https:// and test.
  4. Retry once with backoff since transient rate-limiting from Kuwo is common.
  5. Check whether Kuwo changed the body.code contract by hitting the URL directly in a browser or curl.

Example fix

// before
const { body, statusCode } = await _requestObj.promise
if (statusCode != 200 || body.code != '200') throw new Error('获取评论失败')

// after
const { body, statusCode } = await _requestObj.promise
if (statusCode != 200 || !body || body.code != '200') {
  console.warn('kw getComment failed', { statusCode, code: body?.code })
  throw new Error('获取评论失败')
}
Defensive patterns

Strategy: try-catch

Validate before calling

function isValidKwCommentParams(songmid, page, limit) {
  return typeof songmid === 'string' && songmid.length > 0 && page >= 1 && limit >= 1 && limit <= 100
}

Type guard

function isKwCommentResponse(body) {
  return body != null && typeof body === 'object' && typeof body.code !== 'undefined'
}

Try / catch

try {
  const result = await kwComment.getComment({ songmid }, page, limit)
} catch (err) {
  if (err.message === '获取评论失败') {
    console.warn('Kuwo comments unavailable for', songmid)
    return { source: 'kw', comments: [], total: 0, page, limit, maxPage: 1 }
  }
  throw err
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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