{"record":{"id":"1037cf4575593cda","repo":"jackwener/OpenCLI","slug":"authrequirederror-gitee-com-probe-detail","errorCode":null,"errorMessage":"AuthRequiredError('gitee.com', probe.detail)","messagePattern":"AuthRequiredError\\('gitee\\.com', probe\\.detail\\)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/gitee/auth.js","lineNumber":23,"sourceCode":"// rotates, so the poll uses a no-navigation API probe instead of a cookie gate.\nconst WHOAMI_PROBE = `(async () => {\n  try {\n    const r = await fetch('/api/v5/user', { credentials: 'include', headers: { Accept: 'application/json' } });\n    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Gitee /api/v5/user HTTP ' + r.status };\n    if (!r.ok) return { kind: 'http', httpStatus: r.status };\n    const d = await r.json();\n    if (!d || !d.id || !d.login) return { kind: 'auth', detail: 'Gitee /api/v5/user has no id/login — anonymous' };\n    return { ok: true, user_id: String(d.id), username: String(d.login), name: String(d.name || '') };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyGiteeIdentity(page) {\n  await page.goto('https://gitee.com/');\n  await page.wait(1);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('gitee.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Gitee /api/v5/user`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Gitee whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Gitee probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, username: probe.username, name: probe.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'gitee',\n  domain: 'gitee.com',\n  loginUrl: 'https://gitee.com/login',\n  columns: ['user_id', 'username', 'name'],\n  verify: verifyGiteeIdentity,\n  poll: async (page) => {\n    const probe = await page.evaluate(WHOAMI_PROBE);\n    if (!probe?.ok) throw new AuthRequiredError('gitee.com', 'Waiting for Gitee login');\n    return { user_id: probe.user_id, username: probe.username, name: probe.name };\n  },\n});","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gitee/auth.js#L5-L41","documentation":"verifyGiteeIdentity in clis/gitee/auth.js probes https://gitee.com/api/v5/user from inside the logged-in browser page. When that endpoint answers 401/403, or returns JSON without id/login (anonymous), the probe reports kind 'auth' and this AuthRequiredError('gitee.com', detail) is thrown. It signals that no valid Gitee session exists and an interactive login (https://gitee.com/login) is required before the command can proceed.","triggerScenarios":"Running any Gitee auth command (login --verify / whoami flows registered via registerSiteAuthCommands) while the browser has no valid gitee session cookie: /api/v5/user returns 401 or 403, or returns 200 with an anonymous body lacking id/login.","commonSituations":"Session cookie expired or was revoked on the server; using a fresh browser profile that never logged in; logging out of gitee.com in the automated browser; Gitee invalidating sessions after a password change or security event.","solutions":["Run the gitee login command and complete the interactive login at https://gitee.com/login in the automated browser.","Re-run the whoami/verify command afterwards to confirm the session is valid.","If login keeps failing, clear the browser profile cookies and log in again.","Check that the Gitee account is not suspended and the password has not recently changed (invalidates sessions)."],"exampleFix":"// before — probing identity without a session\nconst who = await verifyGiteeIdentity(page); // throws AuthRequiredError\n// after — catch and prompt login\ntry {\n  const who = await verifyGiteeIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await runGiteeLogin(page); // navigates to https://gitee.com/login\n    const who = await verifyGiteeIdentity(page);\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"const res = await fetch('https://gitee.com/api/v5/user', { credentials: 'include' });\nif (res.status === 401 || res.status === 403) {\n  throw new Error('Not logged in to gitee.com — run login first');\n}","typeGuard":"function isAuthRequiredError(e) { return e && e.name === 'AuthRequiredError'; }","tryCatchPattern":"try {\n  const identity = await verifyGiteeIdentity(page);\n} catch (err) {\n  if (err.name === 'AuthRequiredError') {\n    // launch interactive login at https://gitee.com/login, then re-verify\n  } else throw err;\n}","preventionTips":["Always run the gitee login flow before commands that need identity.","Re-verify the session periodically; cookies expire or are revoked server-side.","Use a persistent browser profile so the session survives restarts.","Catch AuthRequiredError specifically and route to the login URL automatically."],"tags":["gitee","authentication","auth-required","session"],"backgroundTag":"auth-required-login-needed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}