yikart/AiToEarn · error · Error

解析后的数据为空

Error message

解析后的数据为空

What it means

Inside postFormData's JSON-parsing block, if JSON.parse succeeds but the parsed value is falsy (e.g. the body was literally 'null' or '0'), the code logs and throws '解析后的数据为空' (project/aitoearn-electron/electron/plat/douyin/index.ts:2362). Because it is thrown inside the inner try, the outer catch wraps it into '请求失败: 解析后的数据为空' on the last attempt. It means Douyin returned valid JSON that carries no usable payload.

Source

Thrown at project/aitoearn-electron/electron/plat/douyin/index.ts:2362

          if (retryCount < maxRetries - 1) {
            retryCount++;
            console.log(`等待${retryDelay / 1000}秒后重试...`);
            await new Promise((resolve) => setTimeout(resolve, retryDelay));
            continue;
          }

          throw new Error(
            '服务器多次返回空数据,请检查网络连接或抖音服务器状态',
          );
        }

        try {
          const result = JSON.parse(responseText);

          if (!result) {
            console.error(`解析后的数据为空`);
            throw new Error('解析后的数据为空');
          }

          return result;
        } catch (err) {
          console.error(`解析响应数据失败:`, err);
          console.error(`导致错误的原始数据:`, responseText);
          throw new Error(
            `解析响应数据失败: ${err instanceof Error ? err.message : String(err)}`,
          );
        }
      } catch (error) {
        if (retryCount < maxRetries - 1) {
          retryCount++;
          console.log(
            `请求失败,${retryDelay / 1000}秒后进行第${retryCount}次重试...`,
          );
          await new Promise((resolve) => setTimeout(resolve, retryDelay));
          continue;

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Refresh the Douyin cookie/session — a null JSON body almost always means the request was not authenticated properly.
  2. Validate that the target resource (comment id, aweme id) still exists before calling the service.
  3. Log/treat the response as a rejected action and retry with backoff; add larger retryOptions if the failure is intermittent.
  4. Capture the raw responseText (it is logged via console.error) to confirm what the server actually returned.

Example fix

// before
const result = await douyinService.creatorDianzanOther(cookie, data);
// after
try {
  const result = await douyinService.creatorDianzanOther(cookie, data);
} catch (e) {
  if (String(e.message).includes('解析后的数据为空')) {
    // refresh cookie / validate resource before retrying
  }
  throw e;
}
Defensive patterns

Strategy: validation

Validate before calling

function looksLikeDouyinNullBody(text: string): boolean {
  const t = text.trim();
  return t === 'null' || t === '0' || t === '';
}

Type guard

function isParsedResult(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null;
}

Try / catch

try {
  const result = await douyinService.someOp(cookie, data);
} catch (e) {
  if (String(e.message).includes('解析后的数据为空')) {
    await refreshDouyinCookie();
    // verify the target resource still exists before retrying
  } else throw e;
}

Prevention

When it happens

Trigger: responseText parses successfully but evaluates to null/false/0/'' — e.g. Douyin responding with the literal body 'null' — typically for endpoints hit through postFormData with stale auth or a rejected action.

Common situations: Douyin returning 'null' bodies when the session cookie is invalid or the target resource (comment/aweme) no longer exists; risk-control responses that return null JSON instead of an error object; calling after the content was deleted.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/2403acc541c276c6. Report an issue: GitHub.