{"record":{"id":"7e10a2d52f5f1029","repo":"DIYgod/RSSHub","slug":"invalid-api-response","errorCode":null,"errorMessage":"Invalid API response","messagePattern":"Invalid API response","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/bnu/fe.ts","lineNumber":46,"sourceCode":"    try {\n        // 发送 POST 请求\n        response = await got.post(apiUrl, {\n            headers: {\n                Accept: 'application/json, text/javascript, */*; q=0.01',\n                'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',\n                Origin: 'https://fe.bnu.edu.cn',\n                Referer: 'https://fe.bnu.edu.cn/pc/cms1info/list/1/18',\n                'X-Requested-With': 'XMLHttpRequest',\n            },\n            body: `columnid=${category}&page=1`, // POST 数据\n        });\n    } catch {\n        throw new Error('Failed to fetch data from API');\n    }\n    const jsonData = JSON.parse(response.body);\n    // 检查返回的 code\n    if (jsonData.code !== 0 || !jsonData.data) {\n        throw new Error('Invalid API response');\n    }\n\n    const list = jsonData.data.map((item) => ({\n        title: item.title,\n        link: `https://fe.bnu.edu.cn/html/1/news/${item.htmlpath}/n${item.newsid}.html`,\n        pubDate: parseDate(item.happendate, 'YYYY-MM-DD'),\n    }));\n\n    const out = await Promise.all(\n        list.map((item) =>\n            cache.tryGet(item.link, async () => {\n                const response = await got(item.link);\n                const $ = load(response.data);\n                item.author = '北京师范大学教育学部';\n                item.description = $('.news02_div').html() || '暂无详细内容';\n                return item;\n            })\n        )","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bnu/fe.ts#L28-L64","documentation":"Generic Error validating the parsed JSON from BNU's CMS API: it requires code === 0 AND a truthy data field. A 200-OK response whose envelope indicates failure (non-zero code) or lacks the data array is rejected here, before list mapping dereferences it.","triggerScenarios":"got.post succeeded and JSON.parse ran, but jsonData.code is not 0 (e.g. category id rejected, auth required) or jsonData.data is null/undefined/empty. The guard throws before `.map` is called on data.","commonSituations":"Passing a category id the CMS does not recognize; the CMS returning a permission error; the response shape changing so `data` is nested differently; an HTML error page that happened to be JSON-parseable.","solutions":["Log jsonData (code + message keys) to see the CMS's own error description and act on it.","Confirm the category path parameter maps to a valid columnid on the live CMS page.","If the envelope shape changed, update the code/data checks and the list-mapping field names."],"exampleFix":"// before\nif (jsonData.code !== 0 || !jsonData.data) {\n    throw new Error('Invalid API response');\n}\n// after (surface the CMS code/message)\nif (jsonData.code !== 0 || !jsonData.data) {\n    throw new Error(`Invalid API response: code=${jsonData.code}, msg=${jsonData.message ?? 'n/a'}`);\n}","handlingStrategy":"validation","validationCode":"const jsonData = JSON.parse(response.body);\nif (jsonData.code !== 0 || !jsonData.data) {\n    throw new Error(`Invalid API response: code=${jsonData.code}, msg=${jsonData.message ?? 'n/a'}`);\n}","typeGuard":"const isBnuSuccess = (j: any): boolean =>\n    j && j.code === 0 && Array.isArray(j.data);","tryCatchPattern":null,"preventionTips":["Validate the envelope (code + data presence) before mapping.","Surface the CMS code/message so category mismatches are diagnosable.","Confirm the columnid category maps to a real CMS column."],"tags":["bnu","api-error","response-shape","validation"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}