yikart/AiToEarn · error · BadRequestException

获取视频列表失败: ${error.response?.data?.error?.message || error.me

Error message

获取视频列表失败: ${error.response?.data?.error?.message || error.message}

What it means

getUserVideos wraps any failure from TikTok's video-list API (or the local HTTP request) in a 400 BadRequestException whose message embeds TikTok's error.message (error.response.data.error.message) or the generic axios error message. The root cause is upstream — invalid/expired token, bad cursor, TikTok API rejection — re-thrown under a uniform message.

Source

Thrown at project/aitoearn-electron/server/src/modules/plat/tiktok/tiktok.service.ts:74

      };

      if (cursor) {
        params.cursor = cursor;
      }

      const { data } = await firstValueFrom(
        this.httpService.get(`${this.apiBaseUrl}/v2/video/list`, {
          params,
          headers: {
            'Authorization': `Bearer ${accessToken}`
          }
        })
      );

      return data.data;
    } catch (error) {
      this.logger.error('获取TikTok视频列表失败:', error.response?.data || error.message);
      throw new BadRequestException(`获取视频列表失败: ${error.response?.data?.error?.message || error.message}`);
    }
  }

  /**
   * 获取视频详情
   * @param accessToken 访问令牌
   * @param videoId 视频ID
   * @returns 视频详情
   */
  async getVideoDetail(
    accessToken: string,
    videoId: string
  ): Promise<any> {
    try {
      const { data } = await firstValueFrom(
        this.httpService.get(`${this.apiBaseUrl}/v2/video/info/`, {
          params: {
            fields: 'id,create_time,video_description,duration,height,width,share_count,comment_count,like_count,view_count,title,embed_link,embed_html,thumbnail_url',

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Read the embedded error.message from the exception response to identify the TikTok-side cause.
  2. Refresh the TikTok access token via the auth service (getUserAccessToken / refresh flow) and retry.
  3. Validate cursor, max_count, and fields params against TikTok's video-list API contract.
  4. Add retry with backoff for transient TikTok/network failures and rate limits.

Example fix

// before
const videos = await tiktokService.getUserVideos(token, cursor);
// after
try {
  const videos = await tiktokService.getUserVideos(token, cursor);
} catch (e) {
  if (String(e.message).includes('access_token')) {
    token = await refreshAccessToken(accountId);
    return retry();
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!accessToken) throw new Error('No TikTok access token for this account — reconnect the account first');
const expiresAt = getTokenExpiresAt(accountId);
if (expiresAt && expiresAt <= Date.now() + 60_000) await refreshAccessToken(accountId);

Type guard

function isTokenError(msg: string): boolean {
  return /access_token|token.*invalid|token.*expired/i.test(msg);
}

Try / catch

try {
  return await api.post('/tiktok/video/list', { accountId, cursor });
} catch (e) {
  const msg = e.response?.data?.message || e.message;
  if (isTokenError(msg)) {
    await refreshAccessToken(accountId);
    return api.post('/tiktok/video/list', { accountId, cursor });
  }
  if (e.response?.status === 429) await sleep(backoff());
  throw e;
}

Prevention

When it happens

Trigger: Calling getUserVideos with an expired/revoked access token, an invalid cursor/fields parameter, or while TikTok returns a non-2xx response; also on network failure to TikTok.

Common situations: Long-lived integrations whose TikTok OAuth token expired; rate limiting from TikTok; wrong API version/base URL in the service config; sandbox tokens hitting production endpoints.

Related errors


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