{"record":{"id":"e3f53f617bf7b7c5","repo":"DIYgod/RSSHub","slug":"unknown-type-type-e3f53f","errorCode":null,"errorMessage":"Unknown type: ${type}","messagePattern":"Unknown type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":503,"severity":"error","filePath":"lib/routes/whu/cs.ts","lineNumber":58,"sourceCode":"            break;\n\n        case 1:\n            link = `${baseUrl}/kxyj/xsjl.htm`; // 学术交流\n\n            break;\n\n        case 2:\n            link = `${baseUrl}/xwdt/tzgg.htm`; // 通知公告\n\n            break;\n\n        case 3:\n            link = `${baseUrl}/kxyj/kyjz.htm`; // 科研进展\n\n            break;\n\n        default:\n            throw new Error(`Unknown type: ${type}`);\n    }\n\n    const response = await got(link);\n    const $ = load(response.data);\n\n    const list = $('div.study ul li')\n        .toArray()\n        .map((item): DataItem & { link: string } => {\n            const $item = $(item);\n            return {\n                title: $item.find('a p').text().trim(),\n                pubDate: parseDate($item.find('span').text()),\n                link: new URL($item.find('a').attr('href')!, link).href,\n            };\n        });\n\n    let items = (await Promise.all(\n        list.map((item) =>","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/whu/cs.ts#L40-L76","documentation":"Route /whu/cs/:type only accepts integer types 0–3 (学院新闻, 学术交流, 通知公告, 科研进展 per the description table). The handler Number.parseInt's the param and any value outside {0,1,2,3} — including NaN from non-numeric input — falls through to the default branch.","triggerScenarios":"Caller requests /whu/cs/4, /whu/cs/abc, /whu/cs/-1, or omits the segment in a way that yields an unhandled value; Number.parseInt('abc') → NaN fails every case.","commonSituations":"Typo in the route path; copied an example for a different whu sub-route (e.g. swrh uses 0–2); aggregator passing an unsupported category id.","solutions":["Use one of the documented values: 0, 1, 2, or 3 (see the route description table in cs.ts).","Verify the exact path: /whu/cs/<0|1|2|3>.","If you need another category, check whether /whu/rsgis or /whu/swrh covers it instead."],"exampleFix":"// before\n/whu/cs/4\n// after\n/whu/cs/2   // 通知公告","handlingStrategy":"validation","validationCode":"const VALID = new Set([0, 1, 2, 3]);\nconst raw = ctx.req.param('type');\nconst type = Number.parseInt(raw, 10);\nif (!Number.isInteger(type) || !VALID.has(type)) {\n    throw new InvalidParameterError(`/whu/cs/:type must be one of 0,1,2,3 — got ${raw}`);\n}","typeGuard":"function isWhuCsType(v: unknown): v is 0 | 1 | 2 | 3 {\n    const n = Number(v);\n    return Number.isInteger(n) && n >= 0 && n <= 3;\n}","tryCatchPattern":"try {\n    // ...handler body\n} catch (e) {\n    if (e instanceof Error && /^Unknown type:/.test(e.message)) {\n        return ctx.json({ error: 'Invalid type. Use 0,1,2, or 3.' }, 400);\n    }\n    throw e;\n}","preventionTips":["Validate route params at the handler entry with an allow-list rather than relying on switch-default.","Document valid values in the route description and keep selectors in sync.","Return InvalidParameterError (not generic Error) so RSSHub maps it to a 4xx, not a 5xx."],"tags":["whu","route-parameter","validation","switch-default"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}