jackwener/OpenCLI · error · CommandExecutionError

Trip.com package search fetch failed: ${err instanceof Error

Error message

Trip.com package search fetch failed: ${err instanceof Error ? err.message : String(err)}

What it means

fetchPackageSearch wraps the fetch() POST to the Trip.com package search endpoint. If the fetch call itself throws (network unreachable, DNS failure, TLS error, connection reset, timeout), the error is re-thrown as CommandExecutionError prefixed with 'Trip.com package search fetch failed:'. The inner cause's message is appended, so read it to distinguish DNS, TLS, and connection issues.

Source

Thrown at clis/trip/utils.js:955

            Locale: 'en-US', Language: 'en', Currency: 'USD', ClientID: '',
        },
        platform: { src: 'PC', lang: 'en-US', currency: 'USD', sitesrc: 'trip' },
        flightcriteria: {
            osource: 1, triptype: 1, fmap: 19, sflag: 0, rtype: 2,
            seglist: [{ segno: 1, ddate: depart, sgrade: 4, dcode, acode }],
            pinfo: { adults, children: 0, babys: 0 },
        },
        hotelcriteria: { chin: depart, chout: ret, hcityid, rnum: 1 },
    };
    let response;
    try {
        response = await fetch(PACKAGE_SEARCH_ENDPOINT, {
            method: 'POST',
            headers: { 'content-type': 'application/json', currency: 'USD' },
            body: JSON.stringify(body),
        });
    } catch (err) {
        throw new CommandExecutionError(`Trip.com package search fetch failed: ${err instanceof Error ? err.message : String(err)}`);
    }
    if (!response.ok) {
        throw new CommandExecutionError(`Trip.com package search failed with status ${response.status}`);
    }
    let payload;
    try {
        payload = await response.json();
    } catch (err) {
        throw new CommandExecutionError(`Trip.com package search returned invalid JSON: ${err instanceof Error ? err.message : String(err)}`);
    }
    if (!Array.isArray(payload?.grouplist)) {
        throw new CommandExecutionError('Trip.com package search returned malformed payload: missing grouplist array');
    }
    return payload.grouplist;
}

/**
 * Project a package flight group into the stable adapter column shape. A group's

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify connectivity/DNS to the Trip.com package endpoint (curl -v a POST)
  2. Retry with backoff — most fetch-level failures are transient
  3. If behind a proxy, set HTTPS_PROXY and trust the proxy CA via NODE_EXTRA_CA_CERTS
  4. Inspect the appended inner err.message (ENOTFOUND/ECONNRESET/cert errors) to target the specific fix

Example fix

// before
await tripcli(['packages','--from','SHA','--to','HND'])  // no network
// after
await retry(() => tripcli(['packages','--from','SHA','--to','HND']), {retries:3, backoff:2000})
Defensive patterns

Strategy: try-catch

Validate before calling

try { await fetch('https://www.trip.com', { method: 'HEAD' }); } catch (e) { throw new Error('network unavailable before package search: ' + e.message); }

Type guard

null

Try / catch

try {
  const groups = await searchPackages(params);
} catch (e) {
  if (/package search fetch failed:/.test(e.message)) {
    if (/ENOTFOUND|ECONNRESET|ETIMEDOUT/.test(e.message)) return retryWithBackoff(() => searchPackages(params), 3);
    if (/CERT|certificate/.test(e.message)) console.error('TLS issue: check NODE_EXTRA_CA_CERTS / proxy');
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking any command path that goes through groups -> fetchPackageSearch while offline; DNS failure for the endpoint host; proxy/firewall blocking the POST; TLS handshake failure due to missing CA certs; connection reset or timeout during the POST.

Common situations: Corporate proxies intercepting HTTPS without a trusted CA (fix with NODE_EXTRA_CA_CERTS); VPN drops mid-request; IPv6 connectivity issues; transient network blips in CI runners.

Related errors


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