DIYgod/RSSHub · error

message ?? code

Error message

message ?? code

What it means

Thrown by the bilibili coin route when the bilibili space/coin API returns a non-zero code. The error message prefers the API's own message field and falls back to the numeric code, so callers see whatever bilibili reported (e.g. -101 account not logged in, -352 risk control).

Source

Thrown at lib/routes/bilibili/coin.ts:46

    maintainers: ['DIYgod'],
    handler,
};

async function handler(ctx) {
    const uid = ctx.req.param('uid');
    const embed = !ctx.req.param('embed');

    const name = await cache.getUsernameFromUID(uid);

    const response = await got({
        url: `https://api.bilibili.com/x/space/coin/video?vmid=${uid}`,
        headers: {
            Referer: `https://space.bilibili.com/${uid}/`,
        },
    });
    const { data, code, message } = response.data;
    if (code) {
        throw new Error(message ?? code);
    }

    return {
        title: `${name} 的 bilibili 投币视频`,
        link: `https://space.bilibili.com/${uid}`,
        description: `${name} 的 bilibili 投币视频`,
        item: data.map((item) => ({
            title: item.title,
            description: utils.renderUGCDescription(embed, item.pic, item.desc, item.aid, undefined, item.bvid),
            pubDate: parseDate(item.time * 1000),
            link: item.time > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
            author: item.owner.name,
        })),
    };
}

View on GitHub (pinned to bed535e087)

Solutions

  1. Read the message/code from the thrown error: -101 means the request needs a logged-in Cookie (set config.bilibili.cookies[uid]); -352 means risk control — retry later or supply a valid cookie.
  2. Confirm the uid exists and has not hidden coin activity.
  3. If the API moved, update the endpoint in the got call.

Example fix

// before
const { data, code, message } = response.data;
if (code) {
    throw new Error(message ?? code);
}

// after: distinguish auth vs risk-control so the caller can react
if (code) {
    if (code === -101) {
        throw new ConfigNotFoundError(`Bilibili coin API requires a logged-in cookie for uid ${uid} (code -101).`);
    }
    if (code === -352) {
        throw new CaptchaError(`Bilibili risk control triggered for uid ${uid} (code -352). Retry later.`);
    }
    throw new Error(message ?? String(code));
}
Defensive patterns

Strategy: try-catch

Validate before calling

const { code, message, data } = response.data ?? {};
if (code) {
    // known codes: -101 auth, -352 risk control
    throw new Error(message ?? String(code));
}

Type guard

function isBilibiliErrorEnvelope(r: any): boolean {
    return r && typeof r.code === 'number' && r.code !== 0;
}

Try / catch

try {
    const { data, code, message } = response.data;
    if (code) throw new Error(message ?? code);
} catch (e) {
    if (/^-101$/.test(String((e as Error).message))) {
        // refresh/require cookie for uid
    }
    throw e;
}

Prevention

When it happens

Trigger: Requesting /bilibili/coin/:uid and the response.data.code is truthy: the user deleted their coins, the cookie is missing/expired, or bilibili's risk control challenged the request.

Common situations: No/invalid bilibili cookie configured for the target uid; uid does not exist or hid their coin list; bilibili tightened anti-crawler and returned a code like -352.

Related errors


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