{"record":{"id":"ebab3dcb5778039d","repo":"jackwener/OpenCLI","slug":"xq-error","errorCode":null,"errorMessage":"xq-error","messagePattern":"xq-error","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xueqiu/auth.js","lineNumber":44,"sourceCode":"      if (d?.error_code === 60201) {\n        return { kind: 'auth', detail: 'xueqiu portfolio API error_code 60201 用户id无效 — anonymous' };\n      }\n      if (d?.error_code) {\n        return { kind: 'xq-error', errorCode: d.error_code, detail: d.error_description || 'xueqiu API error' };\n      }\n      const uCookie = document.cookie.split('; ').find(c => c.startsWith('u='))?.split('=')[1] || '';\n      const cookiesuCookie = document.cookie.split('; ').find(c => c.startsWith('cookiesu='))?.split('=')[1] || '';\n      if (!uCookie || uCookie === cookiesuCookie) {\n        return { kind: 'auth', detail: 'xueqiu u cookie equals cookiesu (device id) — anonymous despite portfolio API 200' };\n      }\n      return { ok: true, user_id: uCookie };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('xueqiu.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from xueqiu stock API: ${probe.detail || ''}`);\n  if (probe?.kind === 'xq-error') throw new CommandExecutionError(`xueqiu API error_code ${probe.errorCode}: ${probe.detail}`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`xueqiu whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected xueqiu probe: ${JSON.stringify(probe)}`);\n  return { user_id: String(probe.user_id) };\n}\n\nregisterSiteAuthCommands({\n  site: 'xueqiu',\n  domain: 'xueqiu.com',\n  loginUrl: 'https://xueqiu.com/',\n  columns: ['user_id'],\n  quickCheck: hasXueqiuAccessToken,\n  verify: verifyXueqiuIdentity,\n  poll: async (page) => {\n    if (!await hasXueqiuAccessToken(page)) {\n      throw new AuthRequiredError('xueqiu.com', 'Waiting for Xueqiu xq_a_token cookie');\n    }\n    return verifyXueqiuIdentity(page);\n  },","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xueqiu/auth.js#L26-L62","documentation":"verifyXueqiuIdentity probes the xueqiu portfolio API in-page; if the JSON response carries an unexpected error_code other than the anonymous marker 60201, it throws CommandExecutionError with 'xueqiu API error_code <code>: <detail>'. This means xueqiu returned a 200 with a business-level error envelope the verifier does not map to a known auth/HTTP case.","triggerScenarios":"The in-page fetch to stock.xueqiu.com/v5/stock/portfolio/stock/list.json returns ok with body JSON d where d.error_code is truthy and not 60201 (e.g. 400016, 403003 or another site-side business error).","commonSituations":"Xueqiu API contract changes introducing new error codes; account-specific restrictions on the portfolio endpoint; transient site-side errors returned as JSON envelopes.","solutions":["Note the errorCode in the message and search xueqiu docs/community for its meaning","Re-login at https://xueqiu.com/ to refresh xq_a_token and u cookies, then retry verify","Retry later — many xq error codes are transient site-side issues","If persistent after a fresh login, the API contract may have changed; check for library updates"],"exampleFix":"// before\nconst probe = await verifyXueqiuIdentity(page);\n// after (catch and report the code)\ntry {\n  const probe = await verifyXueqiuIdentity(page);\n} catch (e) {\n  console.error('xueqiu verify failed:', e.message); // contains error_code\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isXqErrorProbe(p) {\n  return !!p && typeof p === 'object' && p.kind === 'xq-error' && p.errorCode != null;\n}","tryCatchPattern":"try {\n  await verifyXueqiuIdentity(page);\n} catch (e) {\n  const m = /error_code (\\d+)/.exec(e.message);\n  if (m) console.error(`xueqiu business error ${m[1]} — try re-login`);\n  else throw e;\n}","preventionTips":["Re-login regularly so sessions do not degrade into odd error envelopes","Log the full error message — the errorCode identifies the exact site-side issue","Retry once before escalating; many xq error codes are transient","Track xueqiu API changes if you maintain custom tooling against these endpoints"],"tags":["xueqiu","api-error","error-code"],"backgroundTag":"api-error-code-envelope","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}