DIYgod/RSSHub · error

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

Error message

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

What it means

Raised by the message-unread route when the first of its two parallel calls — https://api.vc.bilibili.com/x/im/web/msgfeed/unread — returns a non-zero business code. (Only msgUnread.code is checked; sessionUnread is read best-effort.) The fallback `Error code N` is used when the upstream omits `message`. Non-zero code means the Cookie reached Bilibili but was rejected at the application layer.

Source

Thrown at lib/routes/bilibili/message-unread.ts:112

                Cookie: cookie,
            },
        }),
        ofetch<UnreadSessionResponse>('https://api.vc.bilibili.com/session_svr/v1/session_svr/single_unread', {
            query: {
                unread_type: 0,
                show_dustbin: 1,
                build: 0,
                mobi_app: 'web',
            },
            headers: {
                Referer: 'https://message.bilibili.com/',
                Cookie: cookie,
            },
        }),
    ]);

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

    const msgData = msgUnread.data;
    const sessionData = sessionUnread.data;

    const items: DataItem[] = [];
    const now = new Date();

    // 回复我的
    if (msgData.recv_reply > 0 || msgData.reply > 0) {
        const replyCount = msgData.recv_reply || msgData.reply;
        items.push({
            title: `回复我的:${replyCount} 条未读`,
            description: `<p>你有 <strong>${replyCount}</strong> 条未读回复消息</p><p><a href="https://message.bilibili.com/#/reply">点击查看</a></p>`,
            link: 'https://message.bilibili.com/#/reply',
            pubDate: now,
            guid: `bilibili-unread-reply-${uid}-${replyCount}`,
        });

View on GitHub (pinned to bed535e087)

Solutions

  1. Refresh BILIBILI_COOKIE_{uid} from a new bilibili.com login (full Cookie including SESSDATA, bili_jct, DedeUserID).
  2. Decode the code: -101 invalid session, -352/-799 risk control, -403 permission.
  3. Increase RSS reader poll interval (>= 10 min); do not run multiple instances against one account.
  4. Verify the cookie's DedeUserID matches the path uid.

Example fix

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

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

Strategy: retry

Validate before calling

import ofetch from '@/utils/ofetch';
import { config } from '@/config';
async function cookieValid(uid: string) {
  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 UnreadEnv<T> { code: number; message?: string; data?: T }
function isUnreadOk<T>(r: UnreadEnv<T>): r is UnreadEnv<T> & { code: 0; data: T } { return r.code === 0; }

Try / catch

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

Prevention

When it happens

Trigger: GET /bilibili/message/unread/:uid with an expired (code -101), rate-limited, or risk-controlled cookie. The msgfeed/unread endpoint is the stricter of the two parallel calls and fails first.

Common situations: Expired SESSDATA; cookie missing bili_jct/DedeUserID; account flagged by risk control from aggressive polling; vc.bilibili.com API contract change.

Related errors


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