jackwener/OpenCLI · error · CommandExecutionError

Ctrip flight API response body was unavailable

Error message

Ctrip flight API response body was unavailable

What it means

This CommandExecutionError is thrown when the captured batchSearch entry has no usable response body — responsePreview is not a string. The library captured the request metadata (URL, status) but could not retrieve the body, so there is nothing to parse. This indicates a capture-layer problem (browser closed, page navigated, CDP body fetch failed) rather than a Ctrip API error.

Source

Thrown at clis/ctrip/flight.js:78

    }
    const captured = entries.filter((entry) => String(entry?.url || '').includes(CAPTURE_PATTERN));
    if (captured.length === 0) return null;

    const byId = new Map();
    let finished = false;
    for (const entry of captured) {
        const status = Number(entry?.responseStatus || 0);
        if (status === 401 || status === 403) {
            throw new AuthRequiredError('flights.ctrip.com', `Ctrip flight API returned HTTP ${status}; complete any verification in the browser and retry`);
        }
        if (status !== 200) {
            throw new CommandExecutionError(`Ctrip flight API returned HTTP ${status || 'unknown'}`);
        }
        if (entry?.responseBodyTruncated === true) {
            throw new CommandExecutionError('Ctrip flight API response exceeded the browser capture limit');
        }
        if (typeof entry?.responsePreview !== 'string') {
            throw new CommandExecutionError('Ctrip flight API response body was unavailable');
        }
        let payload;
        try {
            payload = JSON.parse(entry.responsePreview);
        }
        catch {
            throw new CommandExecutionError('Ctrip flight API returned invalid JSON');
        }
        if (payload?.status !== 0) {
            throw new CommandExecutionError(`Ctrip flight API failed (status=${String(payload?.status)}): ${cleanString(payload?.msg) || 'unknown error'}`);
        }
        const itineraries = payload?.data?.flightItineraryList;
        if (!Array.isArray(itineraries) || typeof payload?.data?.context?.finished !== 'boolean') {
            throw new CommandExecutionError('Ctrip flight API returned a malformed batchSearch payload');
        }
        for (const itinerary of itineraries) {
            const id = cleanString(itinerary?.itineraryId);
            if (!id) throw new CommandExecutionError('Ctrip flight API returned an itinerary without an id');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the search and let the command complete normally before closing or navigating the browser.
  2. Keep the automation browser and the target tab alive until the CLI exits.
  3. Retry — if intermittent, it is likely a CDP/timing race; if consistent, inspect the capture harness version.
  4. Ensure no extensions or navigation scripts redirect the page away from flights.ctrip.com mid-search.

Example fix

// before: close browser as soon as output prints
const rows = await cli.itineraries(args);
await browser.close();
// after: ensure CLI finishes before teardown
const rows = await cli.itineraries(args);
process.on('exit', () => browser.close()); // or await cli completion promise first
Defensive patterns

Strategy: try-catch

Try / catch

try {
  return await cli.itineraries(args);
} catch (err) {
  if (/response body was unavailable/i.test(err.message || '')) {
    // capture race: retry once after short delay, keep browser open
    await sleep(2000);
    return cli.itineraries(args);
  }
  throw err;
}

Prevention

When it happens

Trigger: A captured batchSearch entry where responsePreview is undefined/null/non-string — the page navigated away or the browser closed before the CDP getResponseBody call completed, or the capture harness failed to attach the body to the entry.

Common situations: Scripting the CLI so the browser/tab is closed as soon as results appear; SPA navigation away from the search page during capture; flaky CDP sessions (remote debugging disconnect); response body evicted from the browser cache before retrieval.

Related errors


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