{"record":{"id":"ddb1715cf5e9b800","repo":"jackwener/OpenCLI","slug":"zsxq-com","errorCode":null,"errorMessage":"zsxq.com","messagePattern":"zsxq\\.com","errorType":"error_code","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/zsxq/utils.js","lineNumber":46,"sourceCode":"            const xhr = new XMLHttpRequest();\n            xhr.open('GET', 'https://api.zsxq.com/v2/groups', true);\n            xhr.withCredentials = true;\n            xhr.setRequestHeader('accept', 'application/json');\n            xhr.onload = () => {\n              if (xhr.status >= 200 && xhr.status < 300) {\n                try { resolve(JSON.parse(xhr.responseText)); }\n                catch { resolve(null); }\n              } else { resolve(null); }\n            };\n            xhr.onerror = () => resolve(null);\n            xhr.send();\n          });\n          return r !== null;\n        } catch { return false; }\n      })()\n    `);\n        if (!result) {\n            throw new AuthRequiredError('zsxq.com');\n        }\n    }\n    catch (err) {\n        if (err instanceof AuthRequiredError)\n            throw err;\n        throw new AuthRequiredError('zsxq.com');\n    }\n}\nexport async function getCookieValue(page, name) {\n    const cookies = await page.getCookies({ domain: SITE_DOMAIN });\n    return cookies.find(cookie => cookie.name === name)?.value;\n}\nexport async function getActiveGroupId(page) {\n    const groupId = await page.evaluate(`\n    (() => {\n      const target = localStorage.getItem('target_group');\n      if (target) {\n        try {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zsxq/utils.js#L28-L64","documentation":"ensureZsxqAuth checks the browser session for zsxq login state; on any failure — including exceptions thrown inside the check — it throws AuthRequiredError('zsxq.com'). This is the library's gate telling you that no valid zsxq session exists and the requested operation cannot proceed until you authenticate.","triggerScenarios":"Calling any zsxq command before login: the session probe (cookie/API check) returns false, or the check itself throws (navigation error, closed page), both of which funnel into AuthRequiredError.","commonSituations":"Fresh browser profile with no cookies; session expired since last run; automated run on a machine where the interactive login never happened; browser page crashed during the probe.","solutions":["Run the zsxq login command and complete authentication in the browser, then retry the original command.","Use a persistent browser profile so cookies survive between runs.","Verify manually in the same profile that zsxq.com shows you as logged in.","Catch AuthRequiredError in your automation and trigger the login flow automatically before retrying."],"exampleFix":"// before\nawait listTopics(page); // throws AuthRequiredError\n// after\ntry {\n  await listTopics(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await loginZsxq(page); // interactive flow\n    return listTopics(page);\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// preflight auth check before any zsxq command\nconst r = await page.request.get('https://api.zsxq.com/v2/users/self');\nif (!r.ok()) await loginZsxq(page);","typeGuard":"const isAuthRequired = (e) => e instanceof AuthRequiredError || e?.name === 'AuthRequiredError';","tryCatchPattern":"try {\n  return await runZsxqCommand(args);\n} catch (e) {\n  if (isAuthRequired(e)) {\n    await loginZsxq(page);\n    return runZsxqCommand(args);\n  }\n  throw e;\n}","preventionTips":["Always establish a session (login flow) before invoking zsxq commands.","Use persistent browser storage so cookies persist across runs.","Gate automation runs on a cheap login-state probe instead of failing mid-job."],"tags":["auth","session","login-required"],"backgroundTag":"missing-or-expired-session-auth","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}