DIYgod/RSSHub · error · ConfigNotFoundError

Error code ${response.data.code}: ${message}

Error message

Error code ${response.data.code}: ${message}

What it means

ConfigNotFoundError thrown when Bilibili's /x/v2/history/toview API returns a non-zero code. It is mapped to ConfigNotFoundError (not a generic Error) because the two dominant causes — code -6 (cookie expired) and other auth failures — are configuration problems. The message embeds the raw code and a human-readable hint.

Source

Thrown at lib/routes/bilibili/watchlater.ts:60

    const embed = !ctx.req.param('embed');
    const name = await cache.getUsernameFromUID(uid);

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

    const response = await got({
        method: 'get',
        url: 'https://api.bilibili.com/x/v2/history/toview',
        headers: {
            Referer: `https://space.bilibili.com/${uid}/`,
            Cookie: cookie,
        },
    });
    if (response.data.code) {
        const message = response.data.code === -6 ? '对应 uid 的 Bilibili 用户的 Cookie 已过期' : response.data.message;
        throw new ConfigNotFoundError(`Error code ${response.data.code}: ${message}`);
    }
    const list = response.data.data.list || [];

    const out = list.map((item) => ({
        title: item.title,
        description: utils.renderUGCDescription(embed, item.pic, `${item.desc}<br><a href="https://www.bilibili.com/list/watchlater?bvid=${item.bvid}">在稍后再看列表中查看</a>`, item.aid, undefined, item.bvid),
        pubDate: parseDate(item.add_at * 1000),
        link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
        author: item.owner.name,
    }));

    return {
        title: `${name} 稍后再看`,
        link: 'https://www.bilibili.com/watchlater#/list',
        item: out,
    };
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Re-log in to bilibili.com and update BILIBILI_COOKIE_{uid} with a fresh full Cookie header.
  2. Ensure SESSDATA, bili_jct, and DedeUserID are all present in the stored cookie string.
  3. If the code is not -6, read response.data.message in the logs to identify the specific API rejection and act on it.
  4. Verify the cookie was captured from the same account as the route uid.

Example fix

// before
throw new ConfigNotFoundError(`Error code ${response.data.code}: ${message}`);
// after (surface the exact API message + hint to refresh cookie)
throw new ConfigNotFoundError(`Error code ${response.data.code}: ${message}. Re-login and update BILIBILI_COOKIE_${uid}.`);
Defensive patterns

Strategy: validation

Validate before calling

if (response.data.code) {
    const expired = response.data.code === -6;
    const message = expired ? 'Cookie expired' : response.data.message;
    throw new ConfigNotFoundError(`Error code ${response.data.code}: ${message}`);
}

Type guard

const isApiErrorCode = (data: any): boolean =>
    typeof data?.code === 'number' && data.code !== 0;

Try / catch

try {
    const resp = await got({ ... });
    if (resp.data.code) throw new ConfigNotFoundError(`Error code ${resp.data.code}`);
} catch (e) {
    if (e instanceof ConfigNotFoundError) throw e; // surface auth/config issues to the user
    throw new Error('watchlater request failed: ' + (e as Error).message);
}

Prevention

When it happens

Trigger: The watch-later request reaches the API with a cookie present, but the API responds with code -6 (login expired), -101 (not logged in), -403 (access denied), or any other non-zero status. The handler maps -6 to 'Cookie 已过期' and otherwise uses response.data.message.

Common situations: The SESSDATA in the configured cookie has expired (Bilibili sessions rotate); only a partial cookie was stored (missing SESSDATA); the cookie belongs to a different account than the uid; Bilibili temporarily rate-limits the endpoint.

Related errors


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