{"record":{"id":"2571288bf7925af4","repo":"jackwener/OpenCLI","slug":"nowcoder-com","errorCode":null,"errorMessage":"nowcoder.com","messagePattern":"nowcoder\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/nowcoder/posts.js","lineNumber":247,"sourceCode":"    };\n}\n\nexport function requirePositiveInt(value, name, maximum) {\n    const number = Number(value);\n    if (!Number.isInteger(number) || number < 1 || number > maximum) throw new ArgumentError(`nowcoder --${name} must be an integer from 1 to ${maximum}`);\n    return number;\n}\n\nexport async function fetchNowcoderData(page, url, options, label) {\n    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":229,"sourceCodeEnd":262,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/posts.js#L229-L262","documentation":"fetchNowcoderData navigates a browser page to nowcoder.com and calls the JSON API. If the underlying fetch fails with an HTTP 401/403 status or an error message indicating 'need login' / 'not logged in', the library rethrows it as AuthRequiredError with host 'nowcoder.com', signaling that a valid logged-in Nowcoder session (cookies) is required. The message field of the error is the host string 'nowcoder.com'.","triggerScenarios":"Calling a nowcoder data command while the browser profile has no valid session cookies; session expired; Nowcoder's API returns 401/403 or a 'need login' / 'not logged in' failure for the endpoint.","commonSituations":"Running the CLI in CI or a headless environment without first logging in; cookies expiring after a few days; IP flagged by Nowcoder triggering auth challenges; using a fresh browser profile that never logged in.","solutions":["Log in to https://www.nowcoder.com in the browser profile the CLI uses, then retry.","Refresh/re-establish the session if your cookies expired.","Verify the login by loading a members-only page in that profile.","Avoid running from IPs that trigger auth challenges (datacenter IPs) or use a normal residential connection."],"exampleFix":"// before\n// headless profile without session\nnowcoder posts list  // AuthRequiredError: nowcoder.com\n// after\n// open the profile browser, log in at https://www.nowcoder.com, then rerun\nnowcoder posts list","handlingStrategy":"try-catch","validationCode":"// pre-flight: confirm an active session exists in the CLI's browser profile\n// e.g. open the profile, visit https://www.nowcoder.com, and confirm you are logged in before running commands","typeGuard":null,"tryCatchPattern":"try {\n  const posts = await nowcoderPostsList(opts);\n} catch (err) {\n  if (err instanceof AuthRequiredError && err.message === 'nowcoder.com') {\n    console.error('Log in to www.nowcoder.com in the CLI browser profile, then retry.');\n    process.exitCode = 3;\n  } else throw err;\n}","preventionTips":["Log in to nowcoder.com in the browser profile the CLI drives before running data commands.","Re-login periodically; Nowcoder sessions expire.","Don't run from datacenter IPs that trigger auth challenges.","Verify login state with a quick members-only page check before batch jobs."],"tags":["authentication","session-expired","network"],"backgroundTag":"auth-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}