{"record":{"id":"74860b25dcd1877d","repo":"DIYgod/RSSHub","slug":"invalid-rid","errorCode":null,"errorMessage":"Invalid rid","messagePattern":"Invalid rid","errorType":"exception","errorClass":null,"httpStatus":503,"severity":"error","filePath":"lib/routes/bilibili/ranking.ts","lineNumber":188,"sourceCode":"    handler,\n};\n\nfunction getAPI(isNumericRid: boolean, rid: string | number) {\n    if (isNumericRid) {\n        const zone = ridList[rid as number];\n        return {\n            apiBase: 'https://api.bilibili.com/x/web-interface/ranking/v2',\n            apiParams: `rid=${rid}&type=all&web_location=333.934`,\n            referer: 'https://www.bilibili.com/v/popular/rank/all',\n            ridChinese: zone?.chinese ?? '',\n            ridType: 'x/rid',\n            link: 'https://www.bilibili.com/v/popular/rank/all',\n        };\n    }\n\n    const zone = Object.entries(ridList).find(([_, v]) => v.english === rid);\n    if (!zone) {\n        throw new Error('Invalid rid');\n    }\n    const numericRid = zone[0];\n    const ridType = zone[1].type;\n    const ridChinese = zone[1].chinese;\n    const ridEnglish = zone[1].english;\n\n    let apiBase = 'https://api.bilibili.com/x/web-interface/ranking/v2';\n    let apiParams: string;\n\n    switch (ridType) {\n        case 'x/rid':\n            apiParams = `rid=${numericRid}&type=all&web_location=333.934`;\n            break;\n        case 'pgc/web':\n            apiBase = 'https://api.bilibili.com/pgc/web/rank/list';\n            apiParams = `day=3&season_type=${numericRid}&web_location=333.934`;\n            break;\n        case 'pgc/season':","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/bilibili/ranking.ts#L170-L206","documentation":"Thrown by the bilibili ranking route's getAPI() helper when the `rid` path parameter is a non-numeric token that does not match any `english` value in the static ridList table (the supported English slugs like 'all','douga','music',...). The handler only reaches the Object.entries(...).find(...) lookup for non-numeric rids; a failure there means the slug is unknown to RSSHub. This is a user-input validation error, not a network/upstream failure.","triggerScenarios":"GET /bilibili/ranking/:rid where :rid is non-numeric and not one of the supported English slugs — e.g. /bilibili/ranking/foobar, /bilibili/ranking/anime (anime is not in ridList; the bangumi slug is 'bangumi'), or a typo like /bilibili/ranking/musc.","commonSituations":"Reader subscribes to a slug that does not exist; user guesses a region name that differs from RSSHub's english mapping; outdated documentation pointing at a retired slug; numeric rid passed with trailing characters so the /^\\d+$/ test fails.","solutions":["Use a supported English slug from the route's `parameters.rid.options` (all, douga, game, kichiku, music, dance, cinephile, ent, knowledge, tech, food, car, fashion, sports, animal) or a valid numeric rid (0, 1001–1024).","If you need bangumi/movie/tv/guochuang/documentary/variety rankings, note those are pgc/* types and explicitly unsupported (see error 112).","Strip trailing slashes or query artifacts from the path so the slug matches exactly."],"exampleFix":"// before\n//   /bilibili/ranking/anime   -> throws 'Invalid rid' (no such slug)\n//   /bilibili/ranking/musc     -> throws 'Invalid rid' (typo)\n\n// after\n//   /bilibili/ranking/all\n//   /bilibili/ranking/music\n//   /bilibili/ranking/1003      (numeric rid for music)","handlingStrategy":"validation","validationCode":"// Validate the rid against the supported slugs before calling getAPI().\nimport { config } from '@/config'; // (ridList is module-private in ranking.ts; expose it or mirror it)\n\nconst SUPPORTED_RID_SLUGS = new Set([\n  'all','douga','game','kichiku','music','dance','cinephile','ent',\n  'knowledge','tech','food','car','fashion','sports','animal',\n]);\nconst SUPPORTED_NUMERIC_RIDS = new Set([0,1001,1002,1003,1004,1005,1007,1008,1010,1012,1013,1014,1018,1020,1024]);\n\nfunction isValidRankingRid(rid: string): boolean {\n  if (/^\\d+$/.test(rid)) return SUPPORTED_NUMERIC_RIDS.has(Number(rid));\n  return SUPPORTED_RID_SLUGS.has(rid);\n}","typeGuard":"function isSupportedRankingSlug(rid: string): rid is string {\n  return ['all','douga','game','kichiku','music','dance','cinephile','ent','knowledge','tech','food','car','fashion','sports','animal'].includes(rid);\n}","tryCatchPattern":"try {\n  const { ridType } = getAPI(isNumericRid, rid);\n  // ...\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid rid') {\n    ctx.status = 404;\n    ctx.body = { error: `Unknown rid '${rid}'. Use one of: all, douga, game, ...` };\n    return;\n  }\n  throw e;\n}","preventionTips":["Derive feed URLs only from the route's parameters.rid.options so you never pass an unsupported slug.","Subscribe via numeric rid when in doubt — but remember numeric pgc ids (1-7) route to ridType pgc/* which is blocked (error 112).","Keep a copy of the supported slug list next to your feed reader config and re-check it after RSSHub upgrades."],"tags":["bilibili","validation","input","ranking","rsshub"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}