{"record":{"id":"fae65dc130649fc6","repo":"jackwener/OpenCLI","slug":"unexpected-response-structure","errorCode":null,"errorMessage":"Unexpected response structure","messagePattern":"Unexpected response structure","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/creator-profile.js","lineNumber":41,"sourceCode":"        await page.goto('https://creator.xiaohongshu.com/new/home');\n        const data = await page.evaluate(`\n      async () => {\n        try {\n          const resp = await fetch('/api/galaxy/creator/home/personal_info', {\n            credentials: 'include',\n          });\n          if (!resp.ok) return { error: 'HTTP ' + resp.status };\n          return await resp.json();\n        } catch (e) {\n          return { error: e.message };\n        }\n      }\n    `);\n        if (data?.error) {\n            throw new Error(data.error + '. Are you logged into creator.xiaohongshu.com?');\n        }\n        if (!data?.data) {\n            throw new Error('Unexpected response structure');\n        }\n        const d = data.data;\n        const grow = d.grow_info || {};\n        return [\n            { field: 'Name', value: d.name ?? '' },\n            { field: 'Followers', value: d.fans_count ?? 0 },\n            { field: 'Following', value: d.follow_count ?? 0 },\n            { field: 'Likes & Collects', value: d.faved_count ?? 0 },\n            { field: 'Creator Level', value: grow.level ?? 0 },\n            { field: 'Level Progress', value: `${grow.fans_count ?? 0}/${grow.max_fans_count ?? 0} fans` },\n            { field: 'Bio', value: (d.personal_desc ?? '').replace(/\\\\n/g, ' | ') },\n        ];\n    },\n});\n","sourceCodeStart":23,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/creator-profile.js#L23-L56","documentation":"Thrown by the creator-profile command when the result of the in-page evaluate script has no `data` property. The library expects the Xiaohongshu creator API payload wrapped as `{ data: {...} }`; anything else means the page did not return the expected API envelope. It is a guard against silently formatting undefined fields.","triggerScenarios":"The page.evaluate script resolved with null/undefined, or returned an object without a `data` key (an `{ error }` payload was already handled, so this fires when the payload is neither an error nor the expected envelope).","commonSituations":"Xiaohongshu changed the creator.xiaohongshu.com API response shape; the script ran on a redirected or logged-out page returning an empty/HTML body; a CDN or anti-bot interstitial replaced the JSON response.","solutions":["Log into creator.xiaohongshu.com in the automated browser profile and confirm the dashboard loads manually before rerunning","Log the raw `data` value just before the throw to see what the page actually returned","Check for a Xiaohongshu API/HTML layout change and update the parsing script accordingly","Retry later if an anti-bot or maintenance interstitial is suspected"],"exampleFix":"// before\nif (!data?.data) {\n    throw new Error('Unexpected response structure');\n}\n// after\nif (!data?.data) {\n    console.error('raw evaluate result:', JSON.stringify(data));\n    throw new Error('Unexpected response structure');\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function hasDataEnvelope(v) { return v !== null && typeof v === 'object' && 'data' in v && v.data !== null && typeof v.data === 'object'; }","tryCatchPattern":"try {\n  const profile = await getCreatorProfile();\n} catch (e) {\n  if (e.message === 'Unexpected response structure') {\n    // re-login to creator.xiaohongshu.com, inspect raw payload, or retry\n  } else { throw e; }\n}","preventionTips":["Keep the automation browser profile logged into creator.xiaohongshu.com and verify the dashboard loads before running","Log the raw evaluate result on failure to detect Xiaohongshu schema changes early","Handle anti-bot/interstitial pages before parsing the payload"],"tags":["puppeteer","response-parsing","scraping","api-change"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}