{"record":{"id":"b692b5c75dd4df3a","repo":"DIYgod/RSSHub","slug":"unknown-type-type-b692b5","errorCode":null,"errorMessage":"Unknown type: ${type}","messagePattern":"Unknown type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":503,"severity":"error","filePath":"lib/routes/whu/swrh.ts","lineNumber":58,"sourceCode":"async function handler(ctx) {\n    const type = Number.parseInt(ctx.req.param('type'));\n\n    let link;\n    switch (type) {\n        case 0:\n            link = `${baseUrl}/index/xyxw.htm`; // 学院新闻\n            break;\n\n        case 1:\n            link = `${baseUrl}/index/xsky.htm`; // 学术科研\n            break;\n\n        case 2:\n            link = `${baseUrl}/xxgk/tzgg.htm`; // 通知公告\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 =\n        type === 0\n            ? $('div.my_box_nei')\n                  .toArray()\n                  .map((item): DataItem & { link: string } => {\n                      const $item = $(item);\n                      return {\n                          title: $item.find('a b.am-text-truncate').text().trim(),\n                          pubDate: $item.find('a i').text(),\n                          link: new URL($item.find('a').attr('href')!, baseUrl).href,\n                      };\n                  })\n            : $('div.list_txt.am-fr ul.am-list li')","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/whu/swrh.ts#L40-L76","documentation":"Route /whu/swrh/:type only accepts integer types 0–2 (学院新闻, 学术科研, 通知公告 per the description table). Number.parseInt is applied to the param; anything outside {0,1,2} (including NaN) falls to the default branch.","triggerScenarios":"Caller requests /whu/swrh/3, /whu/swrh/xyz, or any non {0,1,2} value; non-numeric input yields NaN which matches no case.","commonSituations":"Confusing this route with /whu/cs which supports type 3 (科研进展); typo; passing a string category name.","solutions":["Use 0, 1, or 2 only (note: swrh has 3 categories, cs has 4).","Verify the path: /whu/swrh/<0|1|2>.","If you need a 4th category, use /whu/cs instead."],"exampleFix":"// before\n/whu/swrh/3\n// after\n/whu/swrh/2   // 通知公告","handlingStrategy":"validation","validationCode":"const VALID = new Set([0, 1, 2]);\nconst type = Number.parseInt(ctx.req.param('type'), 10);\nif (!Number.isInteger(type) || !VALID.has(type)) {\n    throw new InvalidParameterError(`/whu/swrh/:type must be 0, 1, or 2`);\n}","typeGuard":"function isWhuSwrhType(v: unknown): v is 0 | 1 | 2 {\n    const n = Number(v);\n    return Number.isInteger(n) && n >= 0 && n <= 2;\n}","tryCatchPattern":"try {\n    // handler\n} catch (e) {\n    if (e instanceof Error && /^Unknown type:/.test(e.message)) {\n        throw new InvalidParameterError('Use type 0, 1, or 2 for /whu/swrh');\n    }\n    throw e;\n}","preventionTips":["Note swrh (0–2) and cs (0–3) differ — do not copy example values blindly.","Validate at handler entry and throw InvalidParameterError for clean 4xx mapping.","Unit-test the switch against the full valid set plus one out-of-range value."],"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"}