yikart/AiToEarn · warning · Error

Invalid subtitle data: ${z.prettifyError(result.error)}

Error message

Invalid subtitle data: ${z.prettifyError(result.error)}

What it means

getUserVideos validates queryDto.accountId before resolving the user's TikTok access token. Missing accountId yields a 400 BadRequestException('accountId是必须的'). Unlike checkAuth, this route also requires an authenticated token (systemToken.id) but the account parameter is still mandatory.

Source

Thrown at project/aitoearn-backend/apps/aitoearn-ai/src/core/agent/mcp/video-utils.mcp.ts:407

                },
              },
              { text: prompt },
            ],
          }],
          config: {
            responseMimeType: 'application/json',
            responseJsonSchema: z.toJSONSchema(srtNodesSchema),
          },
        })

        const responseText = response.text
        if (!responseText) {
          throw new Error('No response from Gemini')
        }

        const result = z.safeParse(srtNodesSchema, JSON.parse(responseText))
        if (!result.success) {
          throw new Error(`Invalid subtitle data: ${z.prettifyError(result.error)}`)
        }
        const subtitleData = result.data.map(node => ({
          type: 'cue',
          data: {
            ...node,
            start: srtTimestampToMs(node.start),
            end: srtTimestampToMs(node.end),
          },
        } as const))

        const srtContent = subtitle.stringifySync(subtitleData, { format: 'SRT' })

        this.logger.debug('Uploading SRT file')
        const srtBuffer = Buffer.from(srtContent, 'utf-8')
        const uploadResult = await this.assetsService.uploadFromBuffer(userId, srtBuffer, {
          type: AssetType.Subtitle,
          mimeType: 'text/plain',
          filename: `subtitle-${Date.now()}.srt`,

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Append ?accountId=<id> to the request.
  2. Ensure the UI disables/disables triggering video listing until a TikTok account is selected.
  3. Verify query serialization (e.g. axios params) isn't dropping empty/undefined values silently — select a valid account first.

Example fix

// before
const params = { accountId: selectedAccount?.id, cursor };
await api.get('/plat/tiktok/videos', { params });
// after
if (!selectedAccount?.id) return;
await api.get('/plat/tiktok/videos', { params: { accountId: selectedAccount.id, cursor } });
Defensive patterns

Strategy: validation

Validate before calling

if (!queryDto?.accountId) throw new Error('accountId是必须的');
await api.get('/plat/tiktok/videos', { params: { accountId: queryDto.accountId, cursor: queryDto.cursor } });

Type guard

function hasAccountIdQ(v): v is { accountId: string } {
  return typeof v?.accountId === 'string' && v.accountId.length > 0;
}

Try / catch

try {
  return await api.get('/plat/tiktok/videos', { params: { accountId } });
} catch (e) {
  if (e.response?.status === 400) { promptAccountSelection(); return []; }
  throw e;
}

Prevention

When it happens

Trigger: GET the user-videos route without ?accountId=, or with an empty accountId query value.

Common situations: Pagination UI resets state and drops the account selection, the account list is empty so no ID is selected, or query serialization omits empty values.

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/ec4f8e569fd8f4fe. Report an issue: GitHub.