jackwener/OpenCLI · error · Error

${result.message || result.error || 'API 请求失败'}

Error message

${result.message || result.error || 'API 请求失败'}

What it means

Generic fallback error thrown when the maimai search-talents API returns a non-200/non-0 business code and the response carries no message or error text. It is a plain Error thrown inside in-page JS executed by the CLI after fetching maimai.cn's search endpoint. It signals the API rejected the request in a way the client could not describe.

Source

Thrown at clis/maimai/search-talents.js:121

          'accept': '*/*',
          'content-type': 'text/plain;charset=UTF-8',
          'origin': 'https://maimai.cn',
          'referer': 'https://maimai.cn/ent/talents/discover/search_v2',
          'x-csrf-token': csrftoken,
        },
        credentials: 'include',
        body: JSON.stringify(body),
      });

      const result = await res.json();

      // Check login status
      if (res.status === 401 || res.status === 403 || result.error_code === 20002) {
        throw new Error('需要登录!请先在浏览器中访问 maimai.cn 并登录');
      }

      if (result.code !== 200 && result.code !== 0) {
        throw new Error(result.message || result.error || 'API 请求失败');
      }

      return result;
    }`);

    if (!data || typeof data !== 'object' || Array.isArray(data)) {
      throw new CommandExecutionError('Maimai search returned malformed API payload');
    }

    // Extract talent list from response. Missing list fields mean the API
    // shape drifted; only an explicit empty array is a true empty result.
    const talentListCandidates = [
      data.data?.list,
      data.data?.talent_list,
      data.list,
      data.talent_list,
    ];
    const talentList = talentListCandidates.find((value) => Array.isArray(value));

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-login to maimai.cn in the browser and refresh the session cookie used by the CLI.
  2. Retry later if rate-limited; reduce query frequency.
  3. Log the full result object (add a console.log before the throw) to capture the undocumented code.
  4. Update the CLI if maimai changed its API response shape.

Example fix

// before
throw new Error(result.message || result.error || 'API 请求失败');
// after
console.error('maimai raw response:', JSON.stringify(result));
throw new Error(`API 请求失败 (code=${result.code})`);
Defensive patterns

Strategy: try-catch

Type guard

function hasApiError(result) { return result && typeof result === 'object' && result.code !== 200 && result.code !== 0; }

Try / catch

try {
  const talents = await searchTalents(query);
} catch (e) {
  if (/API 请求失败/.test(e.message)) {
    console.error('maimai rejected the request; check login session and retry later');
  } else throw e;
}

Prevention

When it happens

Trigger: fetch of the maimai search API resolves with an HTTP 200-style wrapper but result.code is neither 200 nor 0, AND result.message/result.error are both falsy.

Common situations: Maimai backend changes its response envelope, rate limiting or anti-bot responses returning empty bodies, expired/invalid session cookies yielding undocumented error codes.

Related errors


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