{"record":{"id":"9155002a263c4755","repo":"DIYgod/RSSHub","slug":"invalid-type-parameter-915500","errorCode":null,"errorMessage":"Invalid type parameter","messagePattern":"Invalid type parameter","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"lib/routes/bupt/jwc.ts","lineNumber":59,"sourceCode":"};\n\nasync function handler(ctx: Context) {\n    let type = ctx.req.param('type'); // 默认类型为通知公告\n    if (!type) {\n        type = 'tzgg';\n    }\n    const rootUrl = 'https://jwc.bupt.edu.cn';\n    let currentUrl;\n    let pageTitle;\n\n    if (type === 'tzgg') {\n        currentUrl = `${rootUrl}/tzgg1.htm`;\n        pageTitle = '通知公告';\n    } else if (type === 'xwzx') {\n        currentUrl = `${rootUrl}/xwzx2.htm`;\n        pageTitle = '新闻资讯';\n    } else {\n        throw new Error('Invalid type parameter');\n    }\n\n    const response = await got({\n        method: 'get',\n        url: currentUrl,\n    });\n\n    const $ = load(response.data);\n\n    const list = $('.txt-elise')\n        .toArray()\n        .map((item): (DataItem & { link: string }) | null => {\n            const $item = $(item);\n            const $link = $item.find('a');\n            // Skip elements without links or with empty href\n            if ($link.length === 0 || !$link.attr('href')) {\n                return null;\n            }","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bupt/jwc.ts#L41-L77","documentation":"Thrown by the BUPT (Beijing University of Posts and Telecommunications) jwc route when the `type` parameter is neither 'tzgg' (通知公告) nor 'xwzx' (新闻资讯). Uses an if/else chain ending in a plain `Error` rather than `InvalidParameterError`, so it is reported as a generic failure.","triggerScenarios":"Requesting `/bupt/jwc/<type>` with type not equal to 'tzgg' or 'xwzx'. Examples that fail: `/bupt/jwc/jwgg`, `/bupt/jwc/bks`, `/bupt/jwc/`.","commonSituations":"Confusing this route's type vocabulary with the buct/gr route's, or guessing a category from the jwc.bupt.edu.cn sidebar that is not wired up here.","solutions":["Use only `/bupt/jwc/tzgg` or `/bupt/jwc/xwzx`.","Maintainers: switch to `InvalidParameterError` and document the two valid values in the route description."],"exampleFix":"// before\nthrow new Error('Invalid type parameter');\n// after\nimport InvalidParameterError from '@/errors/types/invalid-parameter';\nthrow new InvalidParameterError(\"Invalid type parameter. Use 'tzgg' or 'xwzx'\");","handlingStrategy":"validation","validationCode":"const BUPT_JWC_TYPES = ['tzgg', 'xwzx'] as const;\nfunction validateBuptType(type: string): void {\n    if (!(BUPT_JWC_TYPES as readonly string[]).includes(type)) {\n        throw new Error(`Invalid type '${type}'. Use 'tzgg' or 'xwzx'.`);\n    }\n}","typeGuard":"const BUPT_JWC_TYPES = ['tzgg', 'xwzx'] as const;\ntype BuptJwcType = typeof BUPT_JWC_TYPES[number];\nfunction isBuptJwcType(v: string): v is BuptJwcType {\n    return (BUPT_JWC_TYPES as readonly string[]).includes(v);\n}","tryCatchPattern":null,"preventionTips":["Do not reuse the buct/gr or cags/edu vocabulary here — each route has its own type set.","Maintainers: convert the if/else chain to a lookup map and throw `InvalidParameterError`."],"tags":["validation","user-input","route-parameter","if-else-chain"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}