yikart/AiToEarn · error · BadRequestException

videoId, userId和accountId是必须的

Error message

videoId, userId和accountId是必须的

What it means

rateVideo validates that videoId, accountId (from the body) and userId (derived from the authenticated token) are all present before doing anything. A 400 BadRequestException is thrown when any is missing. Note userId comes from systemToken.id, so this error for userId implies the auth token was absent/invalid.

Source

Thrown at project/aitoearn-electron/server/src/modules/plat/tiktok/tiktok.controller.ts:362

    schema: {
      type: 'object',
      properties: {
        accountId: { type: 'string', description: 'TikTok账号ID' },
        videoId: { type: 'string', description: '视频ID' },
        rating: { type: 'string', description: '操作类型: like 或 unlike' }
      },
      required: ['accountId', 'videoId', 'rating']
    }
  })
  async rateVideo(
    @GetToken() systemToken: TokenInfo,
    @Body('videoId') videoId: string,
    @Body('accountId') accountId: string,
    @Body('rating') rating: string
  ) {
    const userId = systemToken.id;
    if (!videoId || !userId || !accountId) {
      throw new BadRequestException('videoId, userId和accountId是必须的');
    }

    const accessToken = await this.tikTokAuthService.getUserAccessToken(accountId);

    // 在方法开始处验证
    if (!["like", "unlike"].includes(rating)) {
      throw new BadRequestException('参数错误: rating必须为like或unlike');
    }

    // 后续处理
    if (rating === "like") {
      return this.tikTokService.likeVideo(accessToken, userId, accountId, videoId);
    } else {
      return this.tikTokService.unlikeVideo(accessToken, userId, accountId, videoId);
    }
  }

  /**

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Include videoId and accountId in the request body.
  2. Attach a valid authentication token so systemToken.id resolves to a userId.
  3. Validate body fields on the client before dispatching the request.

Example fix

// before
await api.post('/tiktok/video/rate', { videoId });
// after
await api.post('/tiktok/video/rate', { videoId, accountId, rating: 'like' });
Defensive patterns

Strategy: validation

Validate before calling

if (!videoId || !accountId || !authToken) {
  throw new Error('videoId, accountId and a valid auth token are required');
}

Type guard

function canRate(p: { videoId?: string; accountId?: string }): p is { videoId: string; accountId: string } {
  return typeof p.videoId === 'string' && p.videoId !== '' &&
         typeof p.accountId === 'string' && p.accountId !== '';
}

Try / catch

try {
  await api.post('/tiktok/video/rate', { videoId, accountId, rating });
} catch (e) {
  if (e.response?.status === 401 || e.response?.status === 400) {
    await reauthenticate();
  }
}

Prevention

When it happens

Trigger: Calling the rate-video endpoint without videoId or accountId in the body, or calling it without a valid auth token so systemToken.id is undefined.

Common situations: Anonymous/unauthenticated requests reaching the endpoint; scripts replaying the endpoint without body fields; account not selected in the UI so accountId is empty.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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