{"record":{"id":"c1b381a08d331419","repo":"DIYgod/RSSHub","slug":"msgunread-message-error-code-msgunread-code","errorCode":null,"errorMessage":"msgUnread.message ?? `Error code ${msgUnread.code}`","messagePattern":"msgUnread\\.message \\?\\? `Error code (.+?)`","errorType":"exception","errorClass":null,"httpStatus":503,"severity":"error","filePath":"lib/routes/bilibili/message-unread.ts","lineNumber":112,"sourceCode":"                Cookie: cookie,\n            },\n        }),\n        ofetch<UnreadSessionResponse>('https://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread', {\n            query: {\n                unread_type: 0,\n                show_dustbin: 1,\n                build: 0,\n                mobi_app: 'web',\n            },\n            headers: {\n                Referer: 'https://message.bilibili.com/',\n                Cookie: cookie,\n            },\n        }),\n    ]);\n\n    if (msgUnread.code !== 0) {\n        throw new Error(msgUnread.message ?? `Error code ${msgUnread.code}`);\n    }\n\n    const msgData = msgUnread.data;\n    const sessionData = sessionUnread.data;\n\n    const items: DataItem[] = [];\n    const now = new Date();\n\n    // 回复我的\n    if (msgData.recv_reply > 0 || msgData.reply > 0) {\n        const replyCount = msgData.recv_reply || msgData.reply;\n        items.push({\n            title: `回复我的：${replyCount} 条未读`,\n            description: `<p>你有 <strong>${replyCount}</strong> 条未读回复消息</p><p><a href=\"https://message.bilibili.com/#/reply\">点击查看</a></p>`,\n            link: 'https://message.bilibili.com/#/reply',\n            pubDate: now,\n            guid: `bilibili-unread-reply-${uid}-${replyCount}`,\n        });","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bilibili/message-unread.ts#L94-L130","documentation":"Raised by the message-unread route when the first of its two parallel calls — https://api.vc.bilibili.com/x/im/web/msgfeed/unread — returns a non-zero business code. (Only msgUnread.code is checked; sessionUnread is read best-effort.) The fallback `Error code N` is used when the upstream omits `message`. Non-zero code means the Cookie reached Bilibili but was rejected at the application layer.","triggerScenarios":"GET /bilibili/message/unread/:uid with an expired (code -101), rate-limited, or risk-controlled cookie. The msgfeed/unread endpoint is the stricter of the two parallel calls and fails first.","commonSituations":"Expired SESSDATA; cookie missing bili_jct/DedeUserID; account flagged by risk control from aggressive polling; vc.bilibili.com API contract change.","solutions":["Refresh BILIBILI_COOKIE_{uid} from a new bilibili.com login (full Cookie including SESSDATA, bili_jct, DedeUserID).","Decode the code: -101 invalid session, -352/-799 risk control, -403 permission.","Increase RSS reader poll interval (>= 10 min); do not run multiple instances against one account.","Verify the cookie's DedeUserID matches the path uid."],"exampleFix":"// before\nif (msgUnread.code !== 0) {\n    throw new Error(msgUnread.message ?? `Error code ${msgUnread.code}`);\n}\n\n// after\nif (msgUnread.code !== 0) {\n    if (msgUnread.code === -101) {\n        throw new ConfigNotFoundError(`Cookie for uid ${uid} expired (code -101). Update BILIBILI_COOKIE_${uid}.`);\n    }\n    throw new Error(msgUnread.message ?? `Error code ${msgUnread.code}`);\n}","handlingStrategy":"retry","validationCode":"import ofetch from '@/utils/ofetch';\nimport { config } from '@/config';\nasync function cookieValid(uid: string) {\n  const cookie = config.bilibili.cookies[uid];\n  if (!cookie) return false;\n  const r = await ofetch<{ code: number }>('https://api.bilibili.com/x/web-interface/nav', { headers: { Cookie: cookie } });\n  return r.code === 0;\n}","typeGuard":"interface UnreadEnv<T> { code: number; message?: string; data?: T }\nfunction isUnreadOk<T>(r: UnreadEnv<T>): r is UnreadEnv<T> & { code: 0; data: T } { return r.code === 0; }","tryCatchPattern":"try {\n  if (msgUnread.code !== 0) throw new Error(msgUnread.message ?? `Error code ${msgUnread.code}`);\n} catch (e) {\n  const m = e instanceof Error ? e.message : '';\n  if (m.includes('-101')) throw new Error(`Refresh BILIBILI_COOKIE_${uid}`);\n  if (m.includes('-352') || m.includes('-799')) await backoffRetry();\n  throw e;\n}","preventionTips":["Health-check each cookie via /x/web-interface/nav periodically.","Cache the unread summary for several minutes; the route already returns allowEmpty:true so a brief cache is safe.","Poll >= 10 minute intervals; avoid running multiple instances against the same account.","Verify DedeUserID matches the path uid."],"tags":["bilibili","api-error","authentication","anti-crawler","rsshub"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}