{"record":{"id":"fe06252b3f36c3b4","repo":"DIYgod/RSSHub","slug":"uid-bilibili-cookie-fe0625","errorCode":null,"errorMessage":"缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值","messagePattern":"缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值","errorType":"exception","errorClass":"ConfigNotFoundError","httpStatus":503,"severity":"error","filePath":"lib/routes/bilibili/message-like.ts","lineNumber":98,"sourceCode":"        };\n        total: {\n            cursor: {\n                is_end: boolean;\n                id: number;\n                time: number;\n            };\n            items: LikeItem[];\n        };\n    };\n}\n\nasync function handler(ctx) {\n    const uid = ctx.req.param('uid');\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 ofetch<LikeResponse>('https://api.bilibili.com/x/msgfeed/like', {\n        query: {\n            platform: 'web',\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 ?? `Error code ${response.code}`);\n    }\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bilibili/message-like.ts#L80-L116","documentation":"Thrown by RSSHub's bilibili 'likes received' route (/bilibili/message/like/:uid) when no Cookie is registered for the requested uid. The handler reads config.bilibili.cookies[uid], which lib/config.ts populates from an env var named BILIBILI_COOKIE_{uid} (e.g. BILIBILI_COOKIE_2267573). If that variable is unset, the lookup returns undefined and the route throws ConfigNotFoundError before calling Bilibili's private https://api.bilibili.com/x/msgfeed/like endpoint, because that endpoint requires an authenticated user session. It is a dedicated Error subclass so RSSHub can surface it as a configuration/authorization failure rather than a generic 500.","triggerScenarios":"Hitting GET /bilibili/message/like/:uid where the {uid} in the URL has no matching BILIBILI_COOKIE_{uid} env var on the RSSHub instance (e.g. requesting /bilibili/message/like/2267573 when only BILIBILI_COOKIE_208259 is set).","commonSituations":"Self-hosted RSSHub operator forgot to add the cookie env var; uid in the feed URL differs from the uid baked into the env var name; env var name typo (BILIBILI_COOKIE without the trailing _UID, or wrong case); cookie configured only in docker-compose but not exported to the container; deploying to a new host without copying the env file.","solutions":["Set the env var BILIBILI_COOKIE_{uid} (replace {uid} with the exact uid from the URL) to the full Cookie header copied from a logged-in bilibili.com browser session, then restart RSSHub.","Verify the env var is actually visible to the process: print config.bilibili.cookies keys in a debug route, or check `env | grep BILIBILI_COOKIE_` in the container.","Confirm the uid in the URL exactly matches the suffix after BILIBILI_COOKIE_ (no leading/trailing spaces, no bv:/ mid prefixes).","If running under Docker, ensure the variable is declared under the `environment:` key or `env_file:` and the container is recreated (`docker compose up -d --force-recreate`)."],"exampleFix":"// before (env):\n//   (no BILIBILI_COOKIE_* set)\n// request: /bilibili/message/like/2267573  ->  ConfigNotFoundError\n\n// after (env):\n//   BILIBILI_COOKIE_2267573=SESSDATA=abc...; bili_jct=...; DedeUserID=2267573; ...\n// then restart RSSHub so lib/config.ts rebuilds config.bilibili.cookies","handlingStrategy":"validation","validationCode":"// Run at RSSHub startup, or in a /debug route, to confirm the env var exists\n// for every uid you intend to serve with /bilibili/message/like/:uid.\nimport { config } from '@/config';\n\nfunction assertBilibiliCookie(uid: string) {\n  if (config.bilibili.cookies[uid] === undefined) {\n    throw new Error(\n      `Missing env var BILIBILI_COOKIE_${uid}. Copy the Cookie header from a logged-in bilibili.com session and set it.`\n    );\n  }\n}\n\n// before subscribing to the feed:\nassertBilibiliCookie('2267573');","typeGuard":"import ConfigNotFoundError from '@/errors/types/config-not-found';\n\nfunction isConfigNotFoundError(e: unknown): e is ConfigNotFoundError {\n  return e instanceof ConfigNotFoundError || (e instanceof Error && e.name === 'ConfigNotFoundError');\n}","tryCatchPattern":"try {\n  await feedHandler(ctx);\n} catch (e) {\n  if (e instanceof Error && e.name === 'ConfigNotFoundError') {\n    // Return a clear 4xx-style 'configuration required' response with setup instructions\n    ctx.status = 503;\n    ctx.body = { error: 'BILIBILI_COOKIE_' + uid + ' env var is required' };\n    return;\n  }\n  throw e;\n}","preventionTips":["Document each message route's required env var (BILIBILI_COOKIE_{uid}) in your deployment README and provision all of them before exposing the feed URLs.","Add a startup self-check that walks every configured bilibili message route and asserts the matching cookie exists.","Keep the uid in the feed URL and the env-var suffix identical — treat the suffix as a string, not a number, to avoid leading-zero mismatches.","Use Docker env_file or a secrets manager so cookie rotations don't require editing compose files by hand."],"tags":["config","authentication","bilibili","cookie","rsshub"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}