{"record":{"id":"ced9fe0788d0dd65","repo":"jackwener/OpenCLI","slug":"trip-com-poisearch-failed-with-status-response-s","errorCode":null,"errorMessage":"Trip.com poiSearch failed with status ${response.status}","messagePattern":"Trip\\.com poiSearch failed with status (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/trip/utils.js","lineNumber":845,"sourceCode":" */\nexport async function fetchPoiSearch(keyword) {\n    let response;\n    try {\n        response = await fetch(POI_SEARCH_ENDPOINT, {\n            method: 'POST',\n            headers: { 'content-type': 'application/json', currency: 'USD' },\n            body: JSON.stringify({\n                key: keyword,\n                mode: '0',\n                tripType: 'RT',\n                Head: { Currency: 'USD', Locale: 'en-US', Source: 'ONLINE', Channel: 'EnglishSite', ClientID: 'opencli-trip' },\n            }),\n        });\n    } catch (err) {\n        throw new CommandExecutionError(`Trip.com poiSearch fetch failed: ${err instanceof Error ? err.message : String(err)}`);\n    }\n    if (!response.ok) {\n        throw new CommandExecutionError(`Trip.com poiSearch 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 poiSearch returned invalid JSON: ${err instanceof Error ? err.message : String(err)}`);\n    }\n    if (!Array.isArray(payload?.results)) {\n        throw new CommandExecutionError('Trip.com poiSearch returned malformed payload: missing results array');\n    }\n    return payload.results;\n}\n\n/**\n * Flatten POI results into a flat suggestion list: each top-level city keeps its\n * own row, and its `childResults` (nearby airports) follow, so a single search\n * surfaces both the city id and the airport codes.\n */","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trip/utils.js#L827-L863","documentation":"After the fetch resolves, fetchPoiSearch checks response.ok. Any non-2xx HTTP status (403 rate limit, 404, 5xx server error, 429 too many requests) is raised as CommandExecutionError with 'Trip.com poiSearch failed with status N'. This means the network round-trip succeeded but Trip.com's server rejected the request.","triggerScenarios":"Hitting the poiSearch endpoint too frequently (429); Trip.com blocking bot-like traffic (403); endpoint path changed (404); Trip.com server-side incident (500/502/503) during a request from a results-calling command.","commonSituations":"Loops issuing many POI searches in quick succession; expired or missing cookies/anti-bot tokens; WAF/CDN rules flagging the client; partial Trip.com outages.","solutions":["Log the full status and response body (via a debug/proxy) to identify the cause","Throttle requests: add delay between calls to avoid 429 rate limiting","Retry with exponential backoff for transient 5xx/429 statuses","Check Trip.com API availability/status; if 403 persists, the request may need updated headers/anti-bot tokens"],"exampleFix":"// before\nfor (const kw of keywords) await search(kw) // hammers endpoint -> 429\n// after\nfor (const kw of keywords) { await search(kw); await sleep(1500) }","handlingStrategy":"retry","validationCode":"// validate request shape before sending to reduce 4xx risk\nif (!keyword || typeof keyword !== 'string') throw new Error('keyword required before calling poiSearch');","typeGuard":"null","tryCatchPattern":"async function searchWithRetry(keyword, retries = 3) {\n  for (let i = 0; i < retries; i++) {\n    try { return await searchAttractions(keyword); }\n    catch (e) {\n      const m = /failed with status (\\d+)/.exec(e.message);\n      if (m && (m[1] === '429' || m[1].startsWith('5')) && i < retries - 1) { await sleep(1000 * 2 ** i); continue; }\n      throw e;\n    }\n  }\n}","preventionTips":["Throttle requests to avoid 429 rate limiting","Backoff-and-retry on 5xx and 429 only; fail fast on 4xx","Watch Trip.com API/schema changes that cause 404/403","Log status + response body for diagnosis"],"tags":["http","api","status-code","rate-limit"],"backgroundTag":"http-non-ok-status","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}