jackwener/OpenCLI · error · CommandExecutionError

HTTP ${probe.httpStatus} from nowcoder profile API

Error message

HTTP ${probe.httpStatus} from nowcoder profile API

What it means

When the in-page probe's fetch to https://gw-c.nowcoder.com/api/sparta/user/profile/<uid> returns a non-OK, non-401/403 status, the probe reports kind:'http' and the library throws CommandExecutionError with 'HTTP <status> from nowcoder profile API'. This signals a server/gateway problem rather than an auth problem.

Source

Thrown at clis/nowcoder/auth.js:47

    const d = await r.json();
    if (!d || !d.success || !d.data || !d.data.id) {
      return { kind: 'auth', detail: 'nowcoder profile returned no user data (anonymous)' };
    }
    return { ok: true, user_id: String(d.data.id), nickname: String(d.data.nickname || '') };
  } catch (e) {
    return { kind: 'exception', detail: String(e && e.message || e) };
  }
})()`;

async function verifyNowcoderIdentity(page) {
  if (!await hasNowcoderSessionCookie(page)) {
    throw new AuthRequiredError('nowcoder.com', 'Nowcoder t cookie missing (anonymous)');
  }
  await page.goto('https://www.nowcoder.com/');
  await page.wait(2);
  const probe = await page.evaluate(WHOAMI_PROBE);
  if (probe?.kind === 'auth') throw new AuthRequiredError('nowcoder.com', probe.detail);
  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from nowcoder profile API`);
  if (probe?.kind === 'exception') throw new CommandExecutionError(`Nowcoder whoami failed: ${probe.detail}`);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected nowcoder probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, nickname: probe.nickname };
}

registerSiteAuthCommands({
  site: 'nowcoder',
  domain: 'nowcoder.com',
  loginUrl: 'https://www.nowcoder.com/login',
  columns: ['user_id', 'nickname'],
  verify: verifyNowcoderIdentity,
  poll: async (page) => {
    if (!await hasNowcoderSessionCookie(page)) {
      throw new AuthRequiredError('nowcoder.com', 'Waiting for Nowcoder login');
    }
    return verifyNowcoderIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Wait and retry after a delay (backoff) — 429/5xx are usually transient
  2. Check https://www.nowcoder.com availability in a browser
  3. If persistent 404, the endpoint changed; update WHOAMI_PROBE to the current profile API URL
  4. Reduce call frequency to avoid rate limiting

Example fix

// before
const who = await verifyNowcoderIdentity(page);
// after
let who;
try {
  who = await verifyNowcoderIdentity(page);
} catch (e) {
  if (/HTTP 4\d\d|HTTP 5\d\d from nowcoder profile API/.test(e.message)) {
    await new Promise(r => setTimeout(r, 5000));
    who = await verifyNowcoderIdentity(page);
  } else throw e;
}
Defensive patterns

Strategy: retry

Validate before calling

// Pre-check reachability before the authed call:
const res = await fetch('https://gw-c.nowcoder.com/api/sparta/health', { method: 'HEAD' }).catch(() => null);
if (!res || res.status >= 500) throw new Error('nowcoder gateway unavailable; retry later');

Type guard

function isHttpProbe(p) { return p?.kind === 'http' && typeof p.httpStatus === 'number'; }

Try / catch

try {
  return await verifyNowcoderIdentity(page);
} catch (e) {
  const m = e.message.match(/HTTP (\d{3}) from nowcoder profile API/);
  if (m && (m[1] === '429' || m[1].startsWith('5'))) {
    await new Promise(r => setTimeout(r, 10_000));
    return verifyNowcoderIdentity(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: Profile API responding 429 (rate limit), 500/502/503 (gateway errors), or 404 (API path changed) while the user is logged in.

Common situations: Hitting the API too frequently (rate limiting); nowcoder gateway maintenance or outages; the sparta profile endpoint path being renamed after a nowcoder API update.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/e465d78746f7e38e. Report an issue: GitHub.