DIYgod/RSSHub · error · ConfigNotFoundError

缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值

Error message

缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值

What it means

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.

Source

Thrown at lib/routes/bilibili/message-like.ts:98

        };
        total: {
            cursor: {
                is_end: boolean;
                id: number;
                time: number;
            };
            items: LikeItem[];
        };
    };
}

async function handler(ctx) {
    const uid = ctx.req.param('uid');
    const name = await cache.getUsernameFromUID(uid);

    const cookie = config.bilibili.cookies[uid];
    if (cookie === undefined) {
        throw new ConfigNotFoundError('缺少对应 uid 的 Bilibili 用户登录后的 Cookie 值');
    }

    const response = await ofetch<LikeResponse>('https://api.bilibili.com/x/msgfeed/like', {
        query: {
            platform: 'web',
            build: 0,
            mobi_app: 'web',
        },
        headers: {
            Referer: 'https://message.bilibili.com/',
            Cookie: cookie,
        },
    });

    if (response.code !== 0) {
        throw new Error(response.message ?? `Error code ${response.code}`);
    }

View on GitHub (pinned to bed535e087)

Solutions

  1. 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.
  2. 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.
  3. Confirm the uid in the URL exactly matches the suffix after BILIBILI_COOKIE_ (no leading/trailing spaces, no bv:/ mid prefixes).
  4. 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`).

Example fix

// before (env):
//   (no BILIBILI_COOKIE_* set)
// request: /bilibili/message/like/2267573  ->  ConfigNotFoundError

// after (env):
//   BILIBILI_COOKIE_2267573=SESSDATA=abc...; bili_jct=...; DedeUserID=2267573; ...
// then restart RSSHub so lib/config.ts rebuilds config.bilibili.cookies
Defensive patterns

Strategy: validation

Validate before calling

// Run at RSSHub startup, or in a /debug route, to confirm the env var exists
// for every uid you intend to serve with /bilibili/message/like/:uid.
import { config } from '@/config';

function assertBilibiliCookie(uid: string) {
  if (config.bilibili.cookies[uid] === undefined) {
    throw new Error(
      `Missing env var BILIBILI_COOKIE_${uid}. Copy the Cookie header from a logged-in bilibili.com session and set it.`
    );
  }
}

// before subscribing to the feed:
assertBilibiliCookie('2267573');

Type guard

import ConfigNotFoundError from '@/errors/types/config-not-found';

function isConfigNotFoundError(e: unknown): e is ConfigNotFoundError {
  return e instanceof ConfigNotFoundError || (e instanceof Error && e.name === 'ConfigNotFoundError');
}

Try / catch

try {
  await feedHandler(ctx);
} catch (e) {
  if (e instanceof Error && e.name === 'ConfigNotFoundError') {
    // Return a clear 4xx-style 'configuration required' response with setup instructions
    ctx.status = 503;
    ctx.body = { error: 'BILIBILI_COOKIE_' + uid + ' env var is required' };
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/fe06252b3f36c3b4. Report an issue: GitHub.