DIYgod/RSSHub · error

response.message ?? `Error code ${response.code}`

Error message

response.message ?? `Error code ${response.code}`

What it means

Raised by the message-reply route when the call to https://api.bilibili.com/x/msgfeed/reply returns a non-zero business code despite an HTTP 200. The Cookie was present but Bilibili rejected the request at the application layer; the upstream `message` (or a fallback 'Error code N') is re-thrown as a plain Error. Typical of expired/invalid sessions or anti-crawler intervention.

Source

Thrown at lib/routes/bilibili/message-reply.ts:115

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

    const response = await ofetch<ReplyResponse>('https://api.bilibili.com/x/msgfeed/reply', {
        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}`);
    }

    const items: DataItem[] = (response.data.items || []).map((item) => {
        const replyUser = item.user;
        const replyItem = item.item;
        const sourceContent = replyItem.source_content;
        const targetContent = replyItem.target_reply_content;
        const rootContent = replyItem.root_reply_content;

        let description = `<p><strong>${replyUser.nickname}</strong> 回复了你:</p>`;
        description += `<blockquote>${sourceContent}</blockquote>`;

        if (targetContent) {
            description += `<p>你的评论:</p><blockquote>${targetContent}</blockquote>`;
        } else if (rootContent) {
            description += `<p>你的评论:</p><blockquote>${rootContent}</blockquote>`;
        }

View on GitHub (pinned to bed535e087)

Solutions

  1. Re-login to bilibili.com and replace BILIBILI_COOKIE_{uid} with the fresh full Cookie (SESSDATA + bili_jct + DedeUserID).
  2. Inspect the code in the message: -101 invalid session, -352/-799 risk control (slow down / rotate account), -403 permission.
  3. Lower your RSS reader poll interval (>= 10 min) and avoid running multiple RSSHub instances against the same account.
  4. Confirm DedeUserID inside the cookie equals the uid in the path.

Example fix

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

// after
if (response.code !== 0) {
    if (response.code === -101) {
        throw new ConfigNotFoundError(`Cookie for uid ${uid} expired (code -101). Update BILIBILI_COOKIE_${uid}.`);
    }
    throw new Error(response.message ?? `Error code ${response.code}`);
}
Defensive patterns

Strategy: retry

Validate before calling

import ofetch from '@/utils/ofetch';
import { config } from '@/config';

async function cookieStillValid(uid: string): Promise<boolean> {
  const cookie = config.bilibili.cookies[uid];
  if (!cookie) return false;
  const r = await ofetch<{ code: number }>('https://api.bilibili.com/x/web-interface/nav', { headers: { Cookie: cookie } });
  return r.code === 0;
}

Type guard

interface BiliEnv<T> { code: number; message?: string; data?: T }
function isBiliOk<T>(r: BiliEnv<T>): r is BiliEnv<T> & { code: 0; data: T } { return r.code === 0; }

Try / catch

try {
  if (response.code !== 0) throw new Error(response.message ?? `Error code ${response.code}`);
} catch (e) {
  const m = e instanceof Error ? e.message : '';
  if (m.includes('-101')) throw new Error(`Refresh BILIBILI_COOKIE_${uid} (session expired)`);
  if (m.includes('-352') || m.includes('-799')) { await sleepThenRetry(); }
  throw e;
}

Prevention

When it happens

Trigger: GET /bilibili/message/reply/:uid where the BILIBILI_COOKIE_{uid} is expired (code -101), triggers risk control (-352/-799), or the cookie's account does not match the path uid.

Common situations: SESSDATA rotated by Bilibili after a security event; cookie copied without bili_jct/DedeUserID; account flagged by risk control from aggressive RSS polling; upstream API contract change.

Related errors


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