jackwener/OpenCLI · error · CommandExecutionError
Trip.com poiSearch returned malformed payload: missing resul
Error message
Trip.com poiSearch returned malformed payload: missing results array
What it means
fetchPoiSearch expects the parsed JSON body to contain a results array (payload?.results). If the JSON parsed fine but results is missing or not an array, it throws CommandExecutionError with 'Trip.com poiSearch returned malformed payload: missing results array'. This indicates the API contract changed or an error envelope was returned with a success status.
Source
Thrown at clis/trip/utils.js:854
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
* own row, and its `childResults` (nearby airports) follow, so a single search
* surfaces both the city id and the airport codes.
*/
export function flattenPoiResults(results) {
const rows = [];
for (const result of results) {
if (!result || typeof result !== 'object') continue;
rows.push(result);
if (Array.isArray(result.childResults)) {
for (const child of result.childResults) {
if (child && typeof child === 'object') rows.push(child);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Log the full parsed payload to see what shape actually came back
- Check for an error/status field inside the payload (e.g. ResponseStatus) and act on it
- Verify your request body/params match the current expected poiSearch contract
- Update the library/parser if Trip.com changed the response schema
Example fix
// before
if (!Array.isArray(payload?.results)) throw ... // payload = {ResponseStatus:{...}}
// after
const results = payload?.results ?? payload?.data?.results;
if (!Array.isArray(results)) throw new Error('payload: ' + JSON.stringify(payload).slice(0,500)) Defensive patterns
Strategy: type-guard
Validate before calling
null
Type guard
function isPoiResults(payload) {
return payload !== null && typeof payload === 'object' && Array.isArray(payload.results);
} Try / catch
try {
const results = await searchAttractions(keyword);
} catch (e) {
if (/malformed payload: missing results array/.test(e.message)) {
console.error('Trip.com payload schema changed or error envelope returned. Dump payload and check for ResponseStatus/error field.');
}
throw e;
} Prevention
- Log the full payload when the shape check fails to spot error envelopes
- Check for ResponseStatus/error fields before assuming success
- Pin/monitor the library version against Trip.com schema drift
- Validate alternate field locations (e.g. payload.data.results) defensively
When it happens
Trigger: Trip.com returns {"ResponseStatus":...,"error":...} instead of results; API schema update renames or nests the results field; request body fields wrong so the server returns an empty error-shape payload.
Common situations: Trip.com silently changing their internal API schema; anti-bot or session-expiry envelopes that still return 200; wrong locale/currency parameters causing an unexpected response shape; caching layers serving stale schemas.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Bilibili ${label} API returned a malformed payload
- Bilibili ${label} API returned malformed data
- Bilibili ${label} API did not return replies
- Bilibili ${label} API returned malformed replies
- Bilibili ${label} API did not return top_replies
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8cb63df8332e0bb4.
Report an issue: GitHub.