jackwener/OpenCLI · error · CommandExecutionError

Trip.com poiSearch fetch failed: ${err instanceof Error ? er

Error message

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

What it means

fetchPoiSearch wraps the underlying fetch() to the Trip.com poiSearch endpoint. If fetch itself throws — network unreachable, DNS failure, TLS error, connection reset, timeout — the error is re-thrown as CommandExecutionError prefixed with 'Trip.com poiSearch fetch failed:'. It is distinct from HTTP status errors, which are reported separately.

Source

Thrown at clis/trip/utils.js:842

 * airport / place matches, so this needs no browser session. Returns the raw
 * `results` array. Missing/non-array `results` means schema drift; an explicit
 * empty array is the only valid empty-result shape.
 */
export async function fetchPoiSearch(keyword) {
    let response;
    try {
        response = await fetch(POI_SEARCH_ENDPOINT, {
            method: 'POST',
            headers: { 'content-type': 'application/json', currency: 'USD' },
            body: JSON.stringify({
                key: keyword,
                mode: '0',
                tripType: 'RT',
                Head: { Currency: 'USD', Locale: 'en-US', Source: 'ONLINE', Channel: 'EnglishSite', ClientID: 'opencli-trip' },
            }),
        });
    } catch (err) {
        throw new CommandExecutionError(`Trip.com poiSearch fetch failed: ${err instanceof Error ? err.message : String(err)}`);
    }
    if (!response.ok) {
        throw new CommandExecutionError(`Trip.com poiSearch failed with status ${response.status}`);
    }
    let payload;
    try {
        payload = await response.json();
    } catch (err) {
        throw new CommandExecutionError(`Trip.com poiSearch returned invalid JSON: ${err instanceof Error ? err.message : String(err)}`);
    }
    if (!Array.isArray(payload?.results)) {
        throw new CommandExecutionError('Trip.com poiSearch returned malformed payload: missing results array');
    }
    return payload.results;
}

/**
 * Flatten POI results into a flat suggestion list: each top-level city keeps its

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check network connectivity and DNS for the Trip.com API host (curl -v the endpoint)
  2. Retry — the error is often transient; add backoff around the CLI invocation
  3. If behind a proxy, set HTTPS_PROXY and ensure the proxy CA is trusted (NODE_EXTRA_CA_CERTS)
  4. Read the inner err.message in the thrown text to identify the exact cause (ENOTFOUND, ECONNRESET, certificate, etc.)

Example fix

// before
await tripcli(['attractions-search','--query','Kyoto'])  // offline laptop
// after
// connect/VPN first, then retry with backoff
await retry(() => tripcli(['attractions-search','--query','Kyoto']), {retries:3, backoff:1000})
Defensive patterns

Strategy: try-catch

Validate before calling

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

Type guard

null

Try / catch

try {
  const results = await searchAttractions(keyword);
} catch (e) {
  if (/poiSearch fetch failed:/.test(e.message)) {
    if (/ENOTFOUND|ECONNRESET|ETIMEDOUT/.test(e.message)) return retryWithBackoff(() => searchAttractions(keyword), 3);
    if (/certificate|CERT/.test(e.message)) { process.env.NODE_EXTRA_CA_CERTS && console.error('check CA bundle'); }
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling any command path that goes through results -> fetchPoiSearch while offline; DNS cannot resolve the Trip.com API host; a proxy/firewall blocks the request; Node lacks a trusted CA for the TLS handshake; transient connection reset mid-handshake.

Common situations: Corporate proxy intercepting HTTPS; VPN dropping mid-request; missing NODE_EXTRA_CA_CERTS on corporate networks; IPv6 misconfiguration; rate-limit-induced connection drops at the network layer.

Related errors


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