DIYgod/RSSHub · error · Error

接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}

Error message

接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}

What it means

Thrown when the Nowcoder hot-subject API (type='1', hot discussion topics) returns a response with a non-zero `code` field. RSSHub delegates the upstream API's `code` and `msg` into the thrown Error, so the message contains the original API error. This is a server-side failure from `gw-c.nowcoder.com/api/sparta/subject/hot-subject`, not a client configuration problem.

Source

Thrown at lib/routes/nowcoder/hots.ts:41

    ],
    name: '牛客热榜',
    description: '牛客热榜,包括热议话题和全站热贴',
    maintainers: ['xia0ne'],
    handler,
    url: 'nowcoder.com/',
};

async function handler(ctx) {
    const type = ctx.req.param('type') ?? '1';
    const limit = Number(ctx.req.query('limit') ?? '20');
    const size = Number.isFinite(limit) && limit > 0 ? limit : 20;

    let link: string;
    if (type === '1') {
        link = `https://gw-c.nowcoder.com/api/sparta/subject/hot-subject?limit=${size}&_=${Date.now()}&t=`;
        const responseBody = (await got.get(link)).data;
        if (responseBody.code !== 0) {
            throw new Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`);
        }
        const data = responseBody.data.result;
        return {
            title: '牛客网-热议话题',
            link: 'https://mnowpick.nowcoder.com/m/discuss/hot',
            description: '牛客网-热议话题',
            item: data.map((item) => ({
                title: item.content,
                description: `<img src="${item.numberIcon}" alt="rank">`,
                link: `https://www.nowcoder.com/creation/subject/${item.uuid}`,
            })),
        };
    }
    if (type === '2') {
        link = `https://gw-c.nowcoder.com/api/sparta/hot-search/top-hot-pc?size=${size}&_=${Date.now()}&t=`;
        const responseBody = (await got.get(link)).data;
        if (responseBody.code !== 0) {
            throw new Error(`接口错误,错误代码: ${responseBody.code},错误原因: ${responseBody.msg}`);

View on GitHub (pinned to bed535e087)

Solutions

  1. Retry the request after a few minutes — the upstream API may be temporarily overloaded.
  2. Manually open the API URL `https://gw-c.nowcoder.com/api/sparta/subject/hot-subject?limit=20&_=<timestamp>&t=` in a browser to check the live `code`/`msg` values.
  3. If the endpoint was deprecated, check the Nowcoder website for the new API path and update `lib/routes/nowcoder/hots.ts` line 38.
  4. If rate-limited, ensure RSSHub is using `config.trueUA` and consider adding caching via `cache.tryGet`.

Example fix

// before
const responseBody = (await got.get(link)).data;
if (responseBody.code !== 0) {
    throw new Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`);
}

// after — cache the result to reduce upstream load
const responseBody = await cache.tryGet(link, async () => (await got.get(link)).data);
if (responseBody.code !== 0) {
    throw new Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`);
}
Defensive patterns

Strategy: retry

Try / catch

// Wrap the upstream API call with retry + cache to absorb transient failures
try {
    const responseBody = await cache.tryGet(link, async () => (await got.get(link)).data);
    if (responseBody.code !== 0) {
        throw new Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`);
    }
} catch (e) {
    logger.error(`Nowcoder hot-subject API failed: ${e}`);
    throw e;
}

Prevention

When it happens

Trigger: Calling the nowcoder hots route with type '1' (or default) when the upstream Nowcoder hot-subject API is rate-limiting, temporarily down, or returns a business error (e.g., code 1001, code -1). The API is hit with a cache-busting `_=${Date.now()}` timestamp query parameter.

Common situations: The Nowcoder gateway is under maintenance or behind a WAF that blocks non-browser User-Agents. The endpoint path was renamed or deprecated upstream. Intermittent transient failures during peak traffic on nowcoder.com.

Related errors


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