{"record":{"id":"4d52947de099ff9a","repo":"jackwener/OpenCLI","slug":"api-failed-4d5294","errorCode":null,"errorMessage":"API failed","messagePattern":"API failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/nowcoder/salary.js","lineNumber":21,"sourceCode":"cli({\n    site: 'nowcoder',\n    name: 'salary',\n    access: 'read',\n    description: 'Salary disclosure 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=858&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 moment = item.momentData || {};\n    const content = item.contentData || {};\n    return {\n      rank: i + 1,\n      title: moment.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: moment.uuid || content.uuid || item.contentId || '',\n    };\n  });\n})()\n` },\n        { filter: 'item.title' },\n        { limit: '${{ args.limit }}' },","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/salary.js#L3-L39","documentation":"The nowcoder salary command's in-page script fetches gw-c.nowcoder.com/api/sparta/home/tab/content (tabId=858, salary tab). When the response has success:false it throws Error(d.msg || 'API failed'); 'API failed' appears when the server supplies no message. It means the salary tab API rejected the request.","triggerScenarios":"Running `nowcoder salary` when the tab/content endpoint returns success:false with no msg — bad page/limit values, absent Nowcoder session cookie, endpoint change, or rate limiting.","commonSituations":"Unauthenticated browser session; Nowcoder retiring or renumbering tabId 858; deep pagination past the last page; transient gateway (gw-c) incidents.","solutions":["Log in to nowcoder.com in the automated browser so the fetch carries session credentials","Start from page 1 with a modest limit and confirm the tab still returns data in a real browser","Retry after a delay if the gateway is throttling","Verify tabId 858 is still valid and update clis/nowcoder/salary.js if the API changed"],"exampleFix":"// before\nif (!d.success) throw new Error(d.msg || 'API failed');\n// after\nif (!r.ok) throw new Error('HTTP ' + r.status);\nconst d = await r.json();\nif (!d.success) throw new Error(d.msg || 'salary API failed (code=' + d.code + ')');","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', 'salary']); }\ncatch (e) {\n  if (String(e.message).includes('API failed')) { await sleep(3000); /* retry once, or re-login */ }\n  else throw e;\n}","preventionTips":["Log in to nowcoder.com in the driving browser before running salary queries","Confirm tabId 858 (salary tab) is still valid after Nowcoder changes","Avoid deep pagination past available pages","Check r.ok before parsing JSON to separate network from business failures"],"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"}