yikart/AiToEarn · error · BadRequestException

删除评论失败: ${error.response?.data?.error?.message || error.mess

Error message

删除评论失败: ${error.response?.data?.error?.message || error.message}

What it means

The catch-all of deleteComment (tiktok.service.ts:838-841). The POST to /v2/comment/delete/ failed and is re-wrapped as BadRequestException('删除评论失败: ...') with TikTok's error message when available. Deleting a comment requires it to belong to the token's user (as author or video owner) and the comment management scope.

Source

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

    commentId: string
  ): Promise<any> {
    try {
      const { data } = await firstValueFrom(
        this.httpService.post(`${this.apiBaseUrl}/v2/comment/delete/`, {
          video_id: videoId,
          comment_id: commentId
        }, {
          headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${accessToken}`
          }
        })
      );

      return { success: true };
    } catch (error) {
      this.logger.error('删除TikTok评论失败:', error.response?.data || error.message);
      throw new BadRequestException(`删除评论失败: ${error.response?.data?.error?.message || error.message}`);
    }
  }

  /**
   * 点赞视频
   * @param accessToken 访问令牌
   * @param userId 用户ID
   * @param accountId TikTok账号ID
   * @param videoId 视频ID
   * @returns 点赞结果
   */
  async likeVideo(
    accessToken: string,
    userId: string,
    accountId: string,
    videoId: string
  ): Promise<any> {
    try {

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Check the '删除TikTok评论失败:' log for TikTok's error code distinguishing not-found from permission errors.
  2. Treat 'comment not found' as already-deleted success to make deletion idempotent.
  3. Verify the app user authored the comment (or owns the video) — other comments cannot be deleted.
  4. Refresh the access token if the error is auth-related and confirm comment scopes are retained.
  5. Retry with backoff only for 5xx/network errors, not for 4xx permission errors.

Example fix

// before
throw new BadRequestException(`删除评论失败: ${...}`);
// after
const code = error.response?.data?.error?.code;
if (code === 'comment_not_found' || code === 'invalid_comment_id') {
  return { success: true, alreadyDeleted: true };
}
throw new BadRequestException(`删除评论失败: ${...}`);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!videoId || !commentId) throw new Error('videoId and commentId are required');

Type guard

null

Try / catch

try {
  await tiktokService.deleteComment(token, videoId, commentId);
} catch (e) {
  if (/not (found|exist)|already.*deleted|invalid_comment/i.test(e.message)) {
    return; // treat as already deleted
  } else if ((e as any).response?.status === 403) {
    // comment not owned by user — surface 'cannot delete others' comments'
  } else throw e;
}

Prevention

When it happens

Trigger: POST /v2/comment/delete/ returns 4xx/5xx: comment_id already deleted or not owned by the user, missing comment scope, video_id/comment_id mismatch, invalid or expired token, or network/5xx failure.

Common situations: Retrying deletion of an already-deleted comment; deleting a comment on someone else's video that the app user didn't author; stale comment_ids cached locally after the comment was removed; token refresh losing scopes.

Related errors


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