{"record":{"id":"faff6767fe0f38bf","repo":"DIYgod/RSSHub","slug":"responsebody-code-responsebody","errorCode":null,"errorMessage":"接口错误，错误代码:${responseBody.code},错误原因:${responseBody.msg}","messagePattern":"接口错误，错误代码:(.+?),错误原因:(.+?)","errorType":"exception","errorClass":"Error","httpStatus":503,"severity":"error","filePath":"lib/routes/nowcoder/hots.ts","lineNumber":41,"sourceCode":"    ],\n    name: '牛客热榜',\n    description: '牛客热榜，包括热议话题和全站热贴',\n    maintainers: ['xia0ne'],\n    handler,\n    url: 'nowcoder.com/',\n};\n\nasync function handler(ctx) {\n    const type = ctx.req.param('type') ?? '1';\n    const limit = Number(ctx.req.query('limit') ?? '20');\n    const size = Number.isFinite(limit) && limit > 0 ? limit : 20;\n\n    let link: string;\n    if (type === '1') {\n        link = `https://gw-c.nowcoder.com/api/sparta/subject/hot-subject?limit=${size}&_=${Date.now()}&t=`;\n        const responseBody = (await got.get(link)).data;\n        if (responseBody.code !== 0) {\n            throw new Error(`接口错误，错误代码:${responseBody.code},错误原因:${responseBody.msg}`);\n        }\n        const data = responseBody.data.result;\n        return {\n            title: '牛客网-热议话题',\n            link: 'https://mnowpick.nowcoder.com/m/discuss/hot',\n            description: '牛客网-热议话题',\n            item: data.map((item) => ({\n                title: item.content,\n                description: `<img src=\"${item.numberIcon}\" alt=\"rank\">`,\n                link: `https://www.nowcoder.com/creation/subject/${item.uuid}`,\n            })),\n        };\n    }\n    if (type === '2') {\n        link = `https://gw-c.nowcoder.com/api/sparta/hot-search/top-hot-pc?size=${size}&_=${Date.now()}&t=`;\n        const responseBody = (await got.get(link)).data;\n        if (responseBody.code !== 0) {\n            throw new Error(`接口错误，错误代码: ${responseBody.code}，错误原因: ${responseBody.msg}`);","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/nowcoder/hots.ts#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the request after a few minutes — the upstream API may be temporarily overloaded.","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.","If the endpoint was deprecated, check the Nowcoder website for the new API path and update `lib/routes/nowcoder/hots.ts` line 38.","If rate-limited, ensure RSSHub is using `config.trueUA` and consider adding caching via `cache.tryGet`."],"exampleFix":"// before\nconst responseBody = (await got.get(link)).data;\nif (responseBody.code !== 0) {\n    throw new Error(`接口错误，错误代码:${responseBody.code},错误原因:${responseBody.msg}`);\n}\n\n// after — cache the result to reduce upstream load\nconst responseBody = await cache.tryGet(link, async () => (await got.get(link)).data);\nif (responseBody.code !== 0) {\n    throw new Error(`接口错误，错误代码:${responseBody.code},错误原因:${responseBody.msg}`);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Wrap the upstream API call with retry + cache to absorb transient failures\ntry {\n    const responseBody = await cache.tryGet(link, async () => (await got.get(link)).data);\n    if (responseBody.code !== 0) {\n        throw new Error(`接口错误，错误代码:${responseBody.code},错误原因:${responseBody.msg}`);\n    }\n} catch (e) {\n    logger.error(`Nowcoder hot-subject API failed: ${e}`);\n    throw e;\n}","preventionTips":["Cache upstream API responses with cache.tryGet to reduce repeated calls.","Monitor the nowcoder API endpoint for deprecation notices.","Use config.trueUA for realistic browser headers."],"tags":["api-error","nowcoder","upstream","chinese-site"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}