jackwener/OpenCLI · error · Error

Unexpected response structure

Error message

Unexpected response structure

What it means

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.

Source

Thrown at clis/xiaohongshu/creator-profile.js:41

        await page.goto('https://creator.xiaohongshu.com/new/home');
        const data = await page.evaluate(`
      async () => {
        try {
          const resp = await fetch('/api/galaxy/creator/home/personal_info', {
            credentials: 'include',
          });
          if (!resp.ok) return { error: 'HTTP ' + resp.status };
          return await resp.json();
        } catch (e) {
          return { error: e.message };
        }
      }
    `);
        if (data?.error) {
            throw new Error(data.error + '. Are you logged into creator.xiaohongshu.com?');
        }
        if (!data?.data) {
            throw new Error('Unexpected response structure');
        }
        const d = data.data;
        const grow = d.grow_info || {};
        return [
            { field: 'Name', value: d.name ?? '' },
            { field: 'Followers', value: d.fans_count ?? 0 },
            { field: 'Following', value: d.follow_count ?? 0 },
            { field: 'Likes & Collects', value: d.faved_count ?? 0 },
            { field: 'Creator Level', value: grow.level ?? 0 },
            { field: 'Level Progress', value: `${grow.fans_count ?? 0}/${grow.max_fans_count ?? 0} fans` },
            { field: 'Bio', value: (d.personal_desc ?? '').replace(/\\n/g, ' | ') },
        ];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log into creator.xiaohongshu.com in the automated browser profile and confirm the dashboard loads manually before rerunning
  2. Log the raw `data` value just before the throw to see what the page actually returned
  3. Check for a Xiaohongshu API/HTML layout change and update the parsing script accordingly
  4. Retry later if an anti-bot or maintenance interstitial is suspected

Example fix

// before
if (!data?.data) {
    throw new Error('Unexpected response structure');
}
// after
if (!data?.data) {
    console.error('raw evaluate result:', JSON.stringify(data));
    throw new Error('Unexpected response structure');
}
Defensive patterns

Strategy: type-guard

Type guard

function hasDataEnvelope(v) { return v !== null && typeof v === 'object' && 'data' in v && v.data !== null && typeof v.data === 'object'; }

Try / catch

try {
  const profile = await getCreatorProfile();
} catch (e) {
  if (e.message === 'Unexpected response structure') {
    // re-login to creator.xiaohongshu.com, inspect raw payload, or retry
  } else { throw e; }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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