lyswhut/lx-music-desktop · error · Error
获取热门评论失败
Error message
获取热门评论失败
What it means
Thrown by Kuwo's getHotComment when the recommended/hot comment API at http://ncomment.kuwo.cn/com.s (type=get_rec_comment) returns a non-200 HTTP status or body.code is not '200'. Structurally identical to error 40 but targets hot/rec comments. Uses the same plain-http endpoint and the same loose-equality guard, so it shares all transport and contract fragility.
Source
Thrown at src/renderer/utils/musicSdk/kw/comment.js:38
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;)',
},
})
const { body, statusCode } = await _requestObj2.promise
if (statusCode != 200 || body.code != '200') throw new Error('获取热门评论失败')
// console.log(body)
const total = body.hot_comments_counts
return {
source: 'kw',
comments: this.filterComment(body.hot_comments),
total,
page,
limit,
maxPage: Math.ceil(total / limit) || 1,
}
},
filterComment(rawList) {
if (!rawList) return []
return rawList.map(item => {
return {
id: item.id,
text: item.msg,View on GitHub (pinned to 9c364b482e)
Solutions
- Distinguish 'no hot comments' from 'API error' by logging body.code and statusCode; if body.code indicates empty results, return an empty list instead of throwing.
- Verify songmid validity before calling getHotComment.
- Retry with backoff for transient failures.
- Test the endpoint URL directly with curl using the Dalvik User-Agent to check if Kuwo changed the contract.
Example fix
// before
if (statusCode != 200 || body.code != '200') throw new Error('获取热门评论失败')
// after
if (statusCode != 200 || !body || body.code != '200') {
console.warn('kw getHotComment failed', { statusCode, code: body?.code })
if (body?.code && body.code !== '200') return { source: 'kw', comments: [], total: 0, page, limit, maxPage: 1 }
throw new Error('获取热门评论失败')
} Defensive patterns
Strategy: fallback
Validate before calling
function canFetchHotComments(songmid) {
return typeof songmid === 'string' && songmid.length > 0
} Type guard
function isKwHotCommentResponse(body) {
return body != null && typeof body === 'object' && typeof body.code !== 'undefined'
} Try / catch
try {
const result = await kwComment.getHotComment({ songmid }, page, limit)
} catch (err) {
if (err.message === '获取热门评论失败') {
console.warn('Kuwo hot comments unavailable for', songmid)
return { source: 'kw', comments: [], total: 0, page, limit, maxPage: 1 }
}
throw err
} Prevention
- Treat 'no hot comments' as a valid empty result, not an error.
- Fall back to regular comments if hot comments are unavailable.
- Log body.code to distinguish empty-results from genuine API errors.
- Validate songmid before calling.
When it happens
Trigger: Calling getHotComment({ songmid }, page, limit) where the song has no hot/recommended comments (Kuwo returns a non-200 body.code). Network interference with ncomment.kuwo.cn. A cancelled or rate-limited request. The same songmid that works for regular comments may return no hot comments.
Common situations: Songs with low popularity have no recommended comments, so Kuwo returns a non-200 code. ISP-level HTTP interception. The app's proxy configuration routes Kuwo traffic through a tunnel that strips headers.
Related errors
AI-assisted analysis of lyswhut/lx-music-desktop@9c364b482e (2026-08-12).
Data as JSON: /api/errors/d75d52b752cd59b2.
Report an issue: GitHub.