{"record":{"id":"5a63e88b4be77ff9","repo":"DIYgod/RSSHub","slug":"dcpcode-and-clsno-cannot-be-used-at-the-same-time","errorCode":null,"errorMessage":"dcpCode and clsNo cannot be used at the same time","messagePattern":"dcpCode and clsNo cannot be used at the same time","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/buaa/lib/space/newbook.tsx","lineNumber":125,"sourceCode":"        requireConfig: false,\n        requirePuppeteer: false,\n        antiCrawler: false,\n        supportRadar: false,\n        supportBT: false,\n        supportPodcast: false,\n        supportScihub: false,\n    },\n};\n\nasync function handler(ctx: Context): Promise<Data> {\n    const path = ctx.req.param('path');\n    const i = path!.indexOf('/');\n    const params = i === -1 ? '' : path!.slice(i + 1);\n    const searchParams = new URLSearchParams(params);\n    const dcpCode = searchParams.get('dcpCode'); // Filter by subject (discipline code)\n    const clsNo = searchParams.get('clsNo'); // Filter by class (Chinese Library Classification)\n    if (dcpCode && clsNo) {\n        throw new Error('dcpCode and clsNo cannot be used at the same time');\n    }\n    searchParams.set('pageSize', '100'); // Max page size. Any larger value will be ignored\n    searchParams.set('page', '1');\n    !dcpCode && !clsNo && searchParams.set('dcpCode', 'nolimit'); // No classification filter\n    const url = `https://space.lib.buaa.edu.cn/meta-local/opac/new/100/${clsNo ? 'byclass' : 'bysubject'}?${searchParams.toString()}`;\n    const { data } = await got(url);\n    const list = (data?.data?.dataList || []) as Book[];\n    const item = await Promise.all(list.map(async (item: Book) => await getItem(item)));\n    const res: Data = {\n        title: '北航图书馆 - 新书速递',\n        item,\n        description: '北京航空航天大学图书馆新书速递',\n        language: 'zh-CN' as Language,\n        link: 'https://space.lib.buaa.edu.cn/space/newBook',\n        author: '北京航空航天大学图书馆',\n        allowEmpty: true,\n        image: 'https://lib.buaa.edu.cn/apple-touch-icon.png',\n    };","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/buaa/lib/space/newbook.tsx#L107-L143","documentation":"The BUAA library new-book route parses the tail of the path as URLSearchParams and supports filtering by subject (dcpCode) OR by Chinese Library Classification (clsNo), but not both. The downstream API selects either a `/bysubject` or `/byclass` endpoint based on which filter is present, so supplying both is ambiguous and the handler throws a generic Error before building the URL.","triggerScenarios":"Calling the route with a path whose query string contains both `dcpCode` and `clsNo`, e.g. `/buaa/space/newbook/dcpCode=CS101/clsNo=TP311`.","commonSituations":"User concatenates two filter URLs thinking they combine; migrating from a bookmarked OPAC URL that carried both params; copy-paste of an exploratory search URL.","solutions":["Supply at most one of dcpCode or clsNo in the path's query string.","Omit both to get the unfiltered feed (the handler sets dcpCode=nolimit for you).","Pick the scheme you want: dcpCode for subject/discipline, clsNo for CLC class."],"exampleFix":"// before\n//   /buaa/space/newbook/dcpCode=CS101/clsNo=TP311\n// after  (subject filter only)\n//   /buaa/space/newbook/dcpCode=CS101","handlingStrategy":"validation","validationCode":"const params = new URLSearchParams(queryTail);\nconst dcpCode = params.get('dcpCode');\nconst clsNo = params.get('clsNo');\nif (dcpCode && clsNo) {\n  // reject early with a clear message before calling the route\n  throw new Error('Choose either dcpCode (subject) or clsNo (CLC class), not both.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Parse the query tail once and assert mutual exclusivity up front.","Document that dcpCode and clsNo are alternatives, not combinable filters."],"tags":["validation","query-params","mutually-exclusive"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}