{"record":{"id":"5192d95ea1353d8d","repo":"DIYgod/RSSHub","slug":"uid-bilibili-cookie-5192d9","errorCode":null,"errorMessage":"缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值","messagePattern":"缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值","errorType":"exception","errorClass":"ConfigNotFoundError","httpStatus":null,"severity":"error","filePath":"lib/routes/bilibili/watchlater.ts","lineNumber":47,"sourceCode":"        supportPodcast: false,\n        supportScihub: false,\n    },\n    name: '用户稍后再看',\n    maintainers: ['JimenezLi'],\n    handler,\n    description: `::: warning\n用户稍后再看需要 b 站登录后的 Cookie 值，所以只能自建，详情见部署页面的配置模块。\n:::`,\n};\n\nasync function handler(ctx) {\n    const uid = ctx.req.param('uid');\n    const embed = !ctx.req.param('embed');\n    const name = await cache.getUsernameFromUID(uid);\n\n    const cookie = config.bilibili.cookies[uid];\n    if (cookie === undefined) {\n        throw new ConfigNotFoundError('缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值');\n    }\n\n    const response = await got({\n        method: 'get',\n        url: 'https://api.bilibili.com/x/v2/history/toview',\n        headers: {\n            Referer: `https://space.bilibili.com/${uid}/`,\n            Cookie: cookie,\n        },\n    });\n    if (response.data.code) {\n        const message = response.data.code === -6 ? '对应 uid 的 Bilibili 用户的 Cookie 已过期' : response.data.message;\n        throw new ConfigNotFoundError(`Error code ${response.data.code}: ${message}`);\n    }\n    const list = response.data.data.list || [];\n\n    const out = list.map((item) => ({\n        title: item.title,","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bilibili/watchlater.ts#L29-L65","documentation":"ConfigNotFoundError thrown by the bilibili/watchlater handler when config.bilibili.cookies[uid] is undefined. The watch-later feed is private and strictly requires the logged-in user's cookie, so a missing entry is treated as a configuration problem rather than a runtime error, surfacing a clear setup message to the operator.","triggerScenarios":"A request to /bilibili/watchlater/:uid where no environment variable BILIBILI_COOKIE_{uid} was provided, so config.bilibili.cookies has no key for that uid.","commonSituations":"Self-hosting RSSHub without setting the per-uid cookie env var; using a uid that was never registered in config; cookie env var typo such as BILIBILI_COOKIE instead of BILIBILI_COOKIE_2267573.","solutions":["Set BILIBILI_COOKIE_{uid} in the environment (replace {uid} with the target user id, e.g. BILIBILI_COOKIE_2267573).","Copy the full Cookie header from a logged-in bilibili.com session (Network panel on api.bilibili.com).","Restart RSSHub so the config module picks up the new env var.","Confirm the uid in the route matches the uid suffix of the env variable name."],"exampleFix":"# before: no env var set -> error\n# after\nexport BILIBILI_COOKIE_2267573='SESSDATA=xxx; bili_jct=yyy; DedeUserID=2267573'","handlingStrategy":"validation","validationCode":"const uid = ctx.req.param('uid');\nif (config.bilibili.cookies[uid] === undefined) {\n    throw new ConfigNotFoundError(`Set BILIBILI_COOKIE_${uid} to use the watchlater feed`);\n}","typeGuard":"const hasCookieForUid = (uid: string): boolean =>\n    typeof config.bilibili.cookies[uid] === 'string' && config.bilibili.cookies[uid].length > 0;","tryCatchPattern":null,"preventionTips":["Document the BILIBILI_COOKIE_{uid} naming convention in deployment docs.","Add a startup health check listing which uids have cookies configured.","Treat a missing cookie as a 4xx-style config error (ConfigNotFoundError), not a 5xx."],"tags":["bilibili","config","authentication","cookie","env"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}