{"record":{"id":"6ec2c13ad480c81b","repo":"jackwener/OpenCLI","slug":"trip-com-package-search-fetch-failed-err-instan","errorCode":null,"errorMessage":"Trip.com package search fetch failed: ${err instanceof Error ? err.message : String(err)}","messagePattern":"Trip\\.com package search fetch failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/trip/utils.js","lineNumber":955,"sourceCode":"            Locale: 'en-US', Language: 'en', Currency: 'USD', ClientID: '',\n        },\n        platform: { src: 'PC', lang: 'en-US', currency: 'USD', sitesrc: 'trip' },\n        flightcriteria: {\n            osource: 1, triptype: 1, fmap: 19, sflag: 0, rtype: 2,\n            seglist: [{ segno: 1, ddate: depart, sgrade: 4, dcode, acode }],\n            pinfo: { adults, children: 0, babys: 0 },\n        },\n        hotelcriteria: { chin: depart, chout: ret, hcityid, rnum: 1 },\n    };\n    let response;\n    try {\n        response = await fetch(PACKAGE_SEARCH_ENDPOINT, {\n            method: 'POST',\n            headers: { 'content-type': 'application/json', currency: 'USD' },\n            body: JSON.stringify(body),\n        });\n    } catch (err) {\n        throw new CommandExecutionError(`Trip.com package search fetch failed: ${err instanceof Error ? err.message : String(err)}`);\n    }\n    if (!response.ok) {\n        throw new CommandExecutionError(`Trip.com package search failed with status ${response.status}`);\n    }\n    let payload;\n    try {\n        payload = await response.json();\n    } catch (err) {\n        throw new CommandExecutionError(`Trip.com package search returned invalid JSON: ${err instanceof Error ? err.message : String(err)}`);\n    }\n    if (!Array.isArray(payload?.grouplist)) {\n        throw new CommandExecutionError('Trip.com package search returned malformed payload: missing grouplist array');\n    }\n    return payload.grouplist;\n}\n\n/**\n * Project a package flight group into the stable adapter column shape. A group's","sourceCodeStart":937,"sourceCodeEnd":973,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/utils.js#L937-L973","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify connectivity/DNS to the Trip.com package endpoint (curl -v a POST)","Retry with backoff — most fetch-level failures are transient","If behind a proxy, set HTTPS_PROXY and trust the proxy CA via NODE_EXTRA_CA_CERTS","Inspect the appended inner err.message (ENOTFOUND/ECONNRESET/cert errors) to target the specific fix"],"exampleFix":"// before\nawait tripcli(['packages','--from','SHA','--to','HND'])  // no network\n// after\nawait retry(() => tripcli(['packages','--from','SHA','--to','HND']), {retries:3, backoff:2000})","handlingStrategy":"try-catch","validationCode":"try { await fetch('https://www.trip.com', { method: 'HEAD' }); } catch (e) { throw new Error('network unavailable before package search: ' + e.message); }","typeGuard":"null","tryCatchPattern":"try {\n  const groups = await searchPackages(params);\n} catch (e) {\n  if (/package search fetch failed:/.test(e.message)) {\n    if (/ENOTFOUND|ECONNRESET|ETIMEDOUT/.test(e.message)) return retryWithBackoff(() => searchPackages(params), 3);\n    if (/CERT|certificate/.test(e.message)) console.error('TLS issue: check NODE_EXTRA_CA_CERTS / proxy');\n  }\n  throw e;\n}","preventionTips":["Wrap package searches in retry-with-backoff for transient failures","Verify proxy env vars (HTTPS_PROXY) and CA trust in corporate environments","Pre-check DNS/connectivity in CI before batch runs","Parse the inner error code to route to the right fix (DNS vs TLS vs reset)"],"tags":["network","fetch","http"],"backgroundTag":"fetch-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}