{"record":{"id":"0a37cd95a9662c19","repo":"jackwener/OpenCLI","slug":"label-failed-message-payload-code","errorCode":null,"errorMessage":"${label} failed: ${message} (${payload.code})","messagePattern":"(.+?) failed: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/nowcoder/posts.js","lineNumber":257,"sourceCode":"    let payload;\n    try {\n        await page.goto('https://www.nowcoder.com');\n        payload = await page.fetchJson(url, options);\n    }\n    catch (error) {\n        const detail = String(error?.message ?? error);\n        if (/HTTP\\s+(401|403)|need login|not logged in/i.test(detail)) {\n            throw new AuthRequiredError('nowcoder.com', `${label} requires a logged-in Nowcoder session`);\n        }\n        throw new CommandExecutionError(`${label} failed: ${detail}`);\n    }\n    if (!isRecord(payload) || typeof payload.success !== 'boolean' || !Number.isSafeInteger(payload.code)) throw new CommandExecutionError(`${label} returned a malformed envelope`);\n    const message = typeof payload.msg === 'string' ? payload.msg : 'unknown error';\n    if (!payload.success || payload.code !== 0) {\n        if (payload.code === 999 || /need login|登录/i.test(message)) {\n            throw new AuthRequiredError('nowcoder.com', `${label} requires a logged-in Nowcoder session: ${message}`);\n        }\n        throw new CommandExecutionError(`${label} failed: ${message} (${payload.code})`);\n    }\n    if (!isRecord(payload.data)) throw new CommandExecutionError(`${label} returned malformed data`);\n    return payload.data;\n}\n","sourceCodeStart":239,"sourceCodeEnd":262,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/posts.js#L239-L262","documentation":"fetchNowcoderData validates every Nowcoder API response envelope: it requires a record with a boolean success and a safe-integer code. When the envelope is well-formed but success is false or code is non-zero — and the code is not 999 / the message does not indicate a login problem — it throws this CommandExecutionError carrying the server-provided msg and code. It is the generic 'Nowcoder API rejected the request' error.","triggerScenarios":"Calling any nowcoder CLI subcommand (via fetchNowcoderData, used by data) while the remote endpoint replies { success:false, code: N } with N !== 999, e.g. rate limiting, invalid parameters, endpoint changes, or transient server errors.","commonSituations":"Nowcoder changes its gateway API (code semantics shift); the request is throttled during heavy scraping; a wrong endpoint URL or POST body shape yields a non-zero business code; server-side incidents return success:false.","solutions":["Read the code and msg in the error message and check Nowcoder API semantics for that code","Retry after a delay — many non-zero codes are transient rate limiting","Log in to nowcoder.com in the driving browser session in case the code is auth-adjacent (code 999 is diverted to AuthRequiredError)","If persistent, inspect clis/nowcoder/posts.js and verify the endpoint URL/body still match the current Nowcoder API"],"exampleFix":"// before\nconst data = await fetchNowcoderData(page, url, opts);\n// after\nlet data;\ntry {\n  data = await fetchNowcoderData(page, url, opts);\n} catch (e) {\n  if (e instanceof CommandExecutionError && /\\(4\\d\\d\\)$/.test(e.message)) {\n    await sleep(2000);\n    data = await fetchNowcoderData(page, url, opts);\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"function checkEnvelope(p){ if (p && typeof p === 'object' && typeof p.success === 'boolean' && Number.isSafeInteger(p.code)) return p; throw new Error('malformed envelope'); }","typeGuard":"function isEnvelope(p){ return !!p && typeof p === 'object' && typeof p.success === 'boolean' && Number.isSafeInteger(p.code); }","tryCatchPattern":"try { const data = await fetchNowcoderData(page, url, opts); }\ncatch (e) {\n  if (e instanceof AuthRequiredError) { /* prompt login */ }\n  else if (e instanceof CommandExecutionError) { console.error('Nowcoder API rejected:', e.message); /* retry or degrade */ }\n  else throw e;\n}","preventionTips":["Log in to nowcoder.com in the automated browser session before scraping","Back off and retry on non-zero codes; many are transient rate limits","Monitor Nowcoder API changes and pin/verify endpoint behavior periodically","Treat error codes in the message as the source of truth for diagnosis"],"tags":["http-api","nowcoder","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"}