{"record":{"id":"dd67e1c1e8729934","repo":"DIYgod/RSSHub","slug":"cookie","errorCode":null,"errorMessage":"缺少对应论坛的cookie.","messagePattern":"缺少对应论坛的cookie\\.","errorType":"exception","errorClass":"ConfigNotFoundError","httpStatus":null,"severity":"error","filePath":"lib/routes/discuz/discuz.ts","lineNumber":105,"sourceCode":"        link: 'link of subforum, require url encoded',\n    },\n    name: '通用子版块',\n    maintainers: ['junfengP', 'pseudoyu'],\n    handler,\n    description: `| Discuz X Series | Discuz 7.x Series |\n| --------------- | ----------------- |\n| x               | 7                 |`,\n};\n\nasync function handler(ctx) {\n    let link = ctx.req.param('link');\n    const ver = ctx.req.param('ver') ? ctx.req.param('ver').toUpperCase() : undefined;\n    const cid = ctx.req.param('cid');\n    link = link.replace(/:\\/\\//, ':/').replace(/:\\//, '://');\n\n    const cookie = cid === undefined ? '' : config.discuz.cookies[cid];\n    if (cookie === undefined) {\n        throw new ConfigNotFoundError('缺少对应论坛的cookie.');\n    }\n\n    const header = {\n        Cookie: cookie,\n    };\n\n    const { response, responseData } = await fetchWithAntiBot(link, header);\n\n    // 若没有指定编码，则默认utf-8\n    const contentType = response.headers['content-type'] || '';\n    let $ = load(iconv.decode(responseData, 'utf-8'));\n    const charset = contentType.match(/charset=([^;]*)/)?.[1] ?? $('meta[charset]').attr('charset') ?? $('meta[http-equiv=\"Content-Type\"]').attr('content')?.split('charset=', 2)?.[1];\n    if (charset?.toLowerCase() !== 'utf-8') {\n        $ = load(iconv.decode(responseData, charset ?? 'utf-8'));\n    }\n\n    const version = ver ? `DISCUZ! ${ver}` : $('head > meta[name=generator]').attr('content');\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/discuz/discuz.ts#L87-L123","documentation":"The Discuz route supports per-forum authentication via cookies stored in config.discuz.cookies, keyed by a cid (cookie ID) parameter. When a cid is provided in the route but no matching cookie is found in the configuration, ConfigNotFoundError is thrown. Without the cookie, the route cannot access forums that require login (to view thread lists, member-only sections, etc.).","triggerScenarios":"ctx.req.param('cid') returns a value, but config.discuz.cookies[cid] is undefined. The handler then checks if cookie === undefined (distinct from an empty string, which is valid for no-cookie access when cid is not provided). If the cid does not map to a configured cookie, the error fires.","commonSituations":"User provides a cid in the route path that was never configured; the environment variable for the cookie was not set or named incorrectly; the cookie expired and was removed from config; typo in the cid parameter.","solutions":["Configure the forum cookie by setting the appropriate DISCUZ_COOKIES_* environment variable in RSSHub's config.","Ensure the cid in the route URL matches the key in config.discuz.cookies.","If the forum doesn't require login, omit the cid parameter entirely from the route path.","Obtain a fresh cookie by logging into the forum in a browser and copying the Cookie header value."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const cid = ctx.req.param('cid');\nconst cookie = cid === undefined ? '' : config.discuz?.cookies?.[cid];\nif (cookie === undefined) {\n    const configured = Object.keys(config.discuz?.cookies || {});\n    throw new ConfigNotFoundError(`Cookie for cid '${cid}' not found. Configured cids: ${configured.join(', ') || 'none'}`);\n}","typeGuard":"function hasDiscuzCookie(cfg: any, cid: string): boolean {\n    return cfg?.discuz?.cookies?.[cid] != null;\n}","tryCatchPattern":null,"preventionTips":["Omit the cid parameter entirely if the forum does not require login.","Configure forum cookies via DISCUZ_COOKIES_* environment variables.","Keep cookies fresh — expired cookies will cause authentication failures downstream.","Use a consistent cid naming convention that matches the config key."],"tags":["discuz","configuration","cookie","authentication","config-not-found"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}