{"record":{"id":"fcb6b5baf27dfc44","repo":"jackwener/OpenCLI","slug":"weread-api-key-rejected-errcode-errcode-err","errorCode":null,"errorMessage":"WEREAD_API_KEY rejected (errcode=${errcode}, ${errmsg}). Regenerate the key and re-export it.","messagePattern":"WEREAD_API_KEY rejected \\(errcode=(.+?), (.+?)\\)\\. Regenerate the key and re-export it\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"critical","filePath":"clis/weread-official/utils.js","lineNumber":134,"sourceCode":"        const detail = error instanceof Error ? error.message : String(error);\n        throw new CommandExecutionError(`weread-official ${apiName} returned invalid JSON`, detail);\n    }\n\n    if (payload && typeof payload === 'object' && payload.upgrade_info) {\n        const info = payload.upgrade_info;\n        const required = info?.required_version ?? info?.version ?? 'unknown';\n        const message = info?.message ?? 'WeRead skill version is outdated';\n        throw new CommandExecutionError(\n            `WeRead skill 需升级: ${message}. Required skill_version=${required}, current=${SKILL_VERSION}`,\n            'Pull the latest weread-skills.zip and bump SKILL_VERSION in clis/weread-official/utils.js.',\n        );\n    }\n\n    const errcode = Number(payload?.errcode ?? 0);\n    if (errcode !== 0) {\n        const errmsg = String(payload?.errmsg ?? 'unknown error');\n        if (AUTH_ERRCODES.has(errcode)) {\n            throw new AuthRequiredError(\n                WEREAD_DOMAIN,\n                `WEREAD_API_KEY rejected (errcode=${errcode}, ${errmsg}). Regenerate the key and re-export it.`,\n            );\n        }\n        throw new CommandExecutionError(\n            `weread-official ${apiName} returned errcode=${errcode}`,\n            errmsg,\n        );\n    }\n\n    return payload;\n}\n\n// ── Formatting helpers ──────────────────────────────────────────────────────\n\n/** Unix timestamp (sec) → YYYY-MM-DD using UTC for stable test snapshots. */\nexport function formatDate(ts) {\n    const seconds = Number(ts);","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weread-official/utils.js#L116-L152","documentation":"The gateway accepted the request (HTTP ok) but returned a business errcode that is in AUTH_ERRCODES, meaning WEREAD_API_KEY was rejected. callGateway throws AuthRequiredError naming the WeRead domain, instructing the key to be regenerated and re-exported.","triggerScenarios":"errcode in AUTH_ERRCODES (e.g. auth/token invalid, key revoked); key deleted from the WeRead console; key past expiry; wrong key exported for the account/domain.","commonSituations":"Rotating keys and forgetting to re-export in the shell/CI secrets; multiple accounts with mismatched keys; long-lived key expiring while a script runs unattended.","solutions":["Regenerate the API key in the WeRead console and copy the new value.","Re-export WEREAD_API_KEY in the current shell (and update CI/secret stores).","Run `weread-official` auth/status check to confirm the new key works.","Ensure no stale key lingers in .env, shell rc files, or credential helpers."],"exampleFix":"// before\nexport WEREAD_API_KEY=revoked_key\n// after\nexport WEREAD_API_KEY=<regenerated_key>\n# then: weread-official search --query test   # to verify","handlingStrategy":"try-catch","validationCode":"if (!process.env.WEREAD_API_KEY) throw new Error('WEREAD_API_KEY is missing — export a valid key first');\nif (!/^\\S{10,}$/.test(process.env.WEREAD_API_KEY)) console.warn('WEREAD_API_KEY looks malformed');","typeGuard":"const isAuthError = (e) => e instanceof AuthRequiredError || (e instanceof CommandExecutionError && /WEREAD_API_KEY rejected/.test(e.message));","tryCatchPattern":"try {\n  return await callGateway(apiName, params);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    console.error(`Re-authenticate with ${e.domain}: regenerate WEREAD_API_KEY and re-export it.`);\n    process.exitCode = 3; // let automation re-run the auth step\n    return null;\n  }\n  throw e;\n}","preventionTips":["Store the key in one canonical place (env/secret manager) and sync shell rc files on rotation","Verify the key with a cheap authenticated call before batch jobs","Set expiry reminders for API keys","Never hardcode keys in scripts"],"tags":["auth","api-key","credentials"],"backgroundTag":"api-key-rejected","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}