{"record":{"id":"66522215eeb1905b","repo":"jackwener/OpenCLI","slug":"api-failed-665222","errorCode":null,"errorMessage":"API failed","messagePattern":"API failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/nowcoder/referral.js","lineNumber":21,"sourceCode":"cli({\n    site: 'nowcoder',\n    name: 'referral',\n    access: 'read',\n    description: 'Internal referral posts',\n    domain: 'www.nowcoder.com',\n    args: [\n        { name: 'page', type: 'int', default: 1, help: 'Page number' },\n        { name: 'limit', type: 'int', default: 15, help: 'Number of items' },\n    ],\n    columns: ['rank', 'title', 'author', 'school', 'likes', 'comments', 'views', 'id'],\n    pipeline: [\n        { navigate: 'https://www.nowcoder.com' },\n        { evaluate: `(async () => {\n  const page = \\${{ args.page }};\n  const limit = \\${{ args.limit }};\n  const r = await fetch('https://gw-c.nowcoder.com/api/sparta/home/tab/content?tabId=861&categoryType=1&pageNo=' + page + '&pageSize=' + limit, {credentials: 'include'});\n  const d = await r.json();\n  if (!d.success) throw new Error(d.msg || 'API failed');\n  return (d.data?.records || []).map((item, i) => {\n    const content = item.contentData || item.momentData || {};\n    return {\n      rank: i + 1,\n      title: content.title || '',\n      author: item.userBrief?.nickname || '',\n      school: item.userBrief?.educationInfo || '',\n      likes: item.frequencyData?.likeCnt || 0,\n      comments: item.frequencyData?.commentCnt || 0,\n      views: item.frequencyData?.viewCnt || 0,\n      id: item.momentData?.uuid || item.contentData?.uuid || item.contentId || '',\n    };\n  });\n})()\n` },\n        { filter: 'item.title' },\n        { limit: '${{ args.limit }}' },\n    ],","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/referral.js#L3-L39","documentation":"The nowcoder referral command evaluates an in-page script that fetches gw-c.nowcoder.com/api/sparta/home/tab/content (tabId=861). If d.success is falsy it throws Error(d.msg || 'API failed'); 'API failed' is the fallback when the API gives no message. This signals the tab-content endpoint refused the request.","triggerScenarios":"Running `nowcoder referral` when the tab/content endpoint returns success:false with no msg — invalid pageNo/pageSize, missing session despite credentials:'include', endpoint removed, or throttling.","commonSituations":"Expired login session on nowcoder.com in the automated browser; Nowcoder changing tabId 861 (referral tab) semantics or removing it; requesting pages beyond available content.","solutions":["Log in to nowcoder.com in the driving browser session so credentials are included","Verify page/limit arguments are in a sane range (start at page 1)","Retry later in case of rate limiting","Check the endpoint/tabId still exists and update clis/nowcoder/referral.js if Nowcoder changed it"],"exampleFix":"// before\nif (!d.success) throw new Error(d.msg || 'API failed');\n// after\nif (!d.success) throw new Error('referral tab-content error: ' + (d.msg || JSON.stringify(d).slice(0,120)));","handlingStrategy":"retry","validationCode":"const pageNo = Math.max(1, Number(page) || 1);\nconst pageSize = Math.min(50, Math.max(1, Number(limit) || 10));","typeGuard":"function tabContentOk(d){ return !!d && typeof d === 'object' && d.success === true && Array.isArray(d.data?.records); }","tryCatchPattern":"try { await run(['nowcoder', 'referral']); }\ncatch (e) {\n  if (String(e.message).includes('API failed')) { await sleep(3000); /* retry once, or check login */ }\n  else throw e;\n}","preventionTips":["Keep the automated browser logged in to nowcoder.com","Start pagination at page 1 and stop when records come back empty","Verify tabId 861 still exists after Nowcoder UI updates","Distinguish HTTP errors from business errors by checking r.ok first"],"tags":["nowcoder","in-page-script","api-error"],"backgroundTag":"api-business-error-code","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}