{"record":{"id":"c9f4137f863e9328","repo":"jackwener/OpenCLI","slug":"auth-required-c9f413","errorCode":"AUTH_REQUIRED","errorMessage":"Not logged in to WeRead","messagePattern":"Not logged in to WeRead","errorType":"exception","errorClass":"CliError","httpStatus":401,"severity":"error","filePath":"clis/weread/ai-outline.js","lineNumber":35,"sourceCode":"    const merged = new Map();\n    for (const c of domainCookies) merged.set(c.name, c);\n    for (const c of apiCookies) merged.set(c.name, c);\n    const cookieHeader = buildCookieHeader(Array.from(merged.values()));\n\n    const resp = await fetch(url, {\n        method: 'POST',\n        headers: {\n            'User-Agent': WEREAD_UA,\n            'Content-Type': 'application/json',\n            'Origin': WEREAD_WEB_ORIGIN,\n            'Referer': `${WEREAD_WEB_ORIGIN}/`,\n            ...(cookieHeader ? { 'Cookie': cookieHeader } : {}),\n        },\n        body: JSON.stringify(body),\n    });\n\n    if (resp.status === 401) {\n        throw new CliError('AUTH_REQUIRED', 'Not logged in to WeRead', 'Please log in to weread.qq.com in Chrome first');\n    }\n\n    let data;\n    try {\n        data = await resp.json();\n    } catch {\n        throw new CliError('PARSE_ERROR', `Invalid JSON response for ${path}`, 'WeRead may have returned an HTML error page');\n    }\n\n    if (data?.errcode === -2010 || data?.errcode === -2012) {\n        throw new CliError('AUTH_REQUIRED', 'Not logged in to WeRead', 'Please log in to weread.qq.com in Chrome first');\n    }\n    if (!resp.ok) {\n        throw new CliError('FETCH_ERROR', `HTTP ${resp.status} for ${path}`, 'WeRead API may be temporarily unavailable');\n    }\n    return data;\n}\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weread/ai-outline.js#L17-L53","documentation":"postWebApiWithCookies posts to the WeRead web API using cookies extracted from a local Chrome login. When the server responds with HTTP 401, it throws this CliError with code AUTH_REQUIRED, meaning the request was not authenticated — the extracted cookies are missing, expired, or no longer accepted by WeRead.","triggerScenarios":"chapterData calling postWebApiWithCookies after the user has logged out of weread.qq.com in Chrome, cookies expired, or no Chrome cookie store exists so no Cookie header is sent.","commonSituations":"Users running the CLI on a machine/browser profile where they never logged into WeRead; sessions invalidated by WeRead after a password change; headless/CI environments with no Chrome profile; cookie extraction breaking after a Chrome version update.","solutions":["Open weread.qq.com in Chrome and log in (again), then re-run the command so fresh cookies are extracted.","Confirm the CLI is reading the same Chrome profile you logged in with (profile selection / env override).","Clear WeRead cookies and log in cleanly if the session is in a half-valid state.","Check whether a Chrome update changed the cookie store format and update/re-authenticate accordingly."],"exampleFix":"// before (headless CI, no Chrome login)\nawait chapterData(bookId);\n// after: pre-authenticate, then retry\nexec('google-chrome --profile-directory=Default https://weread.qq.com'); // log in once\nawait chapterData(bookId);","handlingStrategy":"try-catch","validationCode":"// best-effort pre-check that cookies exist before calling\nconst cookies = await extractChromeCookies('weread.qq.com');\nif (!cookies || !cookies.includes('vid=')) {\n  throw new Error('No WeRead session cookies found — log in to weread.qq.com in Chrome first');\n}","typeGuard":"function hasWeReadCookies(cookieHeader) { return typeof cookieHeader === 'string' && /(?:^|;\\s*)vid=/.test(cookieHeader); }","tryCatchPattern":"try {\n  const data = await chapterData(bookId);\n} catch (e) {\n  if (e instanceof CliError && e.code === 'AUTH_REQUIRED') {\n    console.error('Not logged in. Open weread.qq.com in Chrome and log in, then retry.');\n    process.exitCode = 3;\n  } else throw e;\n}","preventionTips":["Log in to weread.qq.com in Chrome on the same machine/profile before running batch jobs.","Check for an AUTH_REQUIRED code before retrying — retrying auth errors never helps.","Refresh cookies proactively before long-running scripts.","In CI, either persist a valid cookie jar or skip WeRead-dependent steps."],"tags":["authentication","cookies","network"],"backgroundTag":"auth-required-not-logged-in","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}