jackwener/OpenCLI · error · CommandExecutionError

Boss API request failed: ${message}

Error message

Boss API request failed: ${message}

What it means

bossFetch wraps page.evaluate's XHR promise; if the in-page promise rejects (network error, xhr.timeout, or JSON.parse failure on a non-JSON body) and the error is not already a typed library error, it is rethrown as CommandExecutionError 'Boss API request failed: <cause>'. The cause string is one of 'Network Error', 'Timeout', or 'JSON parse failed: <first 200 chars>'.

Source

Thrown at clis/boss/utils.js:139

        xhr.onload = () => {
          try { resolve(JSON.parse(xhr.responseText)); }
          catch(e) { reject(new Error('JSON parse failed: ' + xhr.responseText.substring(0, 200))); }
        };
        xhr.onerror = () => reject(new Error('Network Error'));
        xhr.ontimeout = () => reject(new Error('Timeout'));
        xhr.send(${body ? JSON.stringify(body) : 'null'});
      });
    }
  `;
    let data;
    try {
        data = await page.evaluate(script);
    } catch (error) {
        if (error instanceof AuthRequiredError || error instanceof CommandExecutionError) {
            throw error;
        }
        const message = error instanceof Error ? error.message : String(error);
        throw new CommandExecutionError(`Boss API request failed: ${message}`);
    }
    if (!data || typeof data !== 'object') {
        throw new CommandExecutionError('Boss API returned malformed response');
    }
    // Auto-check auth unless caller opts out
    if (!opts.allowNonZero && data.code !== 0) {
        assertOk(data);
    }
    return data;
}
// ── Convenience helpers ─────────────────────────────────────────────────────
/**
 * Fetch the boss friend (chat) list.
 */
export async function fetchFriendList(page, opts = {}) {
    const pageNum = opts.pageNum ?? 1;
    const jobId = opts.jobId ?? '0';
    const url = `https://${BOSS_DOMAIN}/wapi/zprelation/friend/getBossFriendListV2.json?page=${pageNum}&status=0&jobId=${jobId}`;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command — transient network blips and slow responses often succeed on a second attempt.
  2. Verify the driven Chrome actually has internet and the zhipin.com session (open a tab manually).
  3. Increase the timeout by passing { timeout: 30000 } in opts if the endpoint is consistently slow.
  4. If the cause shows 'JSON parse failed' with HTML, log in again / clear the interstitial (captcha) page in the driven Chrome, then retry.
  5. Check VPN/proxy stability or disable it.

Example fix

// before
const data = await bossFetch(page, url); // 15s default timeout
// after
const data = await bossFetch(page, url, { timeout: 30000 }); // tolerate slow endpoints
Defensive patterns

Strategy: retry

Validate before calling

async function assertOnline(page) {
  const status = await page.evaluate("async () => { try { const r = await fetch('https://www.zhipin.com/favicon.ico', { method: 'HEAD' }); return r.ok; } catch { return false; } }");
  if (!status) throw new Error('Driven Chrome has no connectivity to zhipin.com');
}

Type guard

function isTransientFetchFailure(err) {
  return err instanceof CommandExecutionError &&
    /Boss API request failed: (Network Error|Timeout)/.test(err.message);
}

Try / catch

try {
  return await bossFetch(page, url);
} catch (e) {
  if (isTransientFetchFailure(e)) {
    await sleep(2000);
    return bossFetch(page, url, { timeout: 30000 });
  }
  throw e;
}

Prevention

When it happens

Trigger: XHR onerror (connection reset, DNS, offline browser), xhr.ontimeout after 15s (default) on a slow wapi endpoint, or a response body that isn't valid JSON (HTML anti-bot/login page) triggering the in-page parse rejection.

Common situations: Machine or the driven Chrome losing connectivity mid-command; BOSS serving heavy pages or slow endpoints beyond the 15s timeout; BOSS returning an HTML captcha/login interstitial instead of JSON; VPN/proxy dropping.

Related errors


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