{"record":{"id":"f298c68a7457b842","repo":"DIYgod/RSSHub","slug":"response-message-response-msg-error-code","errorCode":null,"errorMessage":"response.message ?? response.msg ?? `Error code ${response.code}`","messagePattern":"response\\.message \\?\\? response\\.msg \\?\\? `Error code (.+?)`","errorType":"exception","errorClass":null,"httpStatus":503,"severity":"error","filePath":"lib/routes/bilibili/message-sessions.ts","lineNumber":169,"sourceCode":"    }\n\n    const response = await ofetch<SessionResponse>('https://api.vc.bilibili.com/session_svr/v1/session_svr/get_sessions', {\n        query: {\n            session_type: 1,\n            group_fold: 1,\n            unfollow_fold: 0,\n            sort_rule: 2,\n            build: 0,\n            mobi_app: 'web',\n        },\n        headers: {\n            Referer: 'https://message.bilibili.com/',\n            Cookie: cookie,\n        },\n    });\n\n    if (response.code !== 0) {\n        throw new Error(response.message ?? response.msg ?? `Error code ${response.code}`);\n    }\n\n    const sessionList = response.data.session_list || [];\n    const talkerIds = sessionList.filter((s) => s.session_type === 1).map((s) => s.talker_id);\n\n    // Fetch user info for all talkers\n    let userCards: Record<string, UserInfo> = {};\n    if (talkerIds.length > 0) {\n        const userCardsResponse = await cache.tryGet(\n            `bilibili-user-cards-${talkerIds.join(',')}`,\n            async () => {\n                const res = await ofetch<UserCardsResponse>('https://api.bilibili.com/x/polymer/pc-electron/v1/user/cards', {\n                    query: {\n                        uids: talkerIds.join(','),\n                        build: 0,\n                        mobi_app: 'web',\n                    },\n                    headers: {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bilibili/message-sessions.ts#L151-L187","documentation":"Thrown by the message-sessions route after https://api.vc.bilibili.com/session_svr/.../get_sessions returns HTTP 200 with a non-zero business code. The fallback chain (response.message ?? response.msg ?? `Error code N`) reflects that some bilibili session endpoints report the human text under `message` and others under `msg`; both are tried before a bare code. A non-zero code means the Cookie was transmitted but Bilibili rejected the call at the application layer.","triggerScenarios":"GET /bilibili/message/sessions/:uid where the configured cookie is expired (code -101), the account is rate-limited, or risk control flagged the session (-352). The dual message/msg lookup fires for both the vc.bilibili.com and x.bilibili.com response shapes.","commonSituations":"Expired SESSDATA; cookie missing bili_jct/DedeUserID; account under anti-crawler cooldown from frequent polling; bilibili changed which field carries the error text (hence the defensive ?? chain).","solutions":["Refresh BILIBILI_COOKIE_{uid} from a new bilibili.com login (full Cookie including SESSDATA, bili_jct, DedeUserID).","Decode the numeric code: -101 session invalid, -352/-799 risk control (slow down / rotate), -403 permission.","Increase the RSS reader poll interval (>= 10 min) and avoid duplicate instances hammering the same account.","Verify the cookie's DedeUserID matches the uid in the path."],"exampleFix":"// before\nif (response.code !== 0) {\n    throw new Error(response.message ?? response.msg ?? `Error code ${response.code}`);\n}\n\n// after\nif (response.code !== 0) {\n    if (response.code === -101) {\n        throw new ConfigNotFoundError(`Cookie for uid ${uid} expired (code -101). Update BILIBILI_COOKIE_${uid}.`);\n    }\n    throw new Error(response.message ?? response.msg ?? `Error code ${response.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":"// vc.bilibili.com envelopes may carry the text in `message` or `msg`\ninterface VcEnv<T> { code: number; message?: string; msg?: string; data?: T }\nfunction isVcOk<T>(r: VcEnv<T>): r is VcEnv<T> & { code: 0; data: T } { return r.code === 0; }","tryCatchPattern":"try {\n  if (response.code !== 0) throw new Error(response.message ?? response.msg ?? `Error code ${response.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":["Periodically validate the cookie via /x/web-interface/nav.","Cache session list output for several minutes (cache.tryGet).","Poll >= 10 minute intervals; avoid duplicate instances per account.","Confirm 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"}