yikart/AiToEarn · error · Error
Failed to create generation task
Error message
Failed to create generation task
What it means
The draft-box plan detail store calls the backend video/audio generation-task API; any response with code !== 0 throws `new Error(res?.message || 'Failed to create generation task')`. Per project API convention, code 0 is success, so this is a backend-reported failure (auth, quota, invalid params, model unavailable) surfaced as a generic fallback message when the response has no message.
Source
Thrown at project/aitoearn-web/src/store/draft-box/planDetailStore.ts:611
const resolvedAspectRatio = inputAspectRatio ?? aspectRatio
const res = await apiCreateDraftGeneration({
quantity,
groupId,
model: modelType,
duration: resolvedDuration,
resolution,
aspectRatio: resolvedAspectRatio,
prompt,
captionPrompt: captionPrompt || undefined,
imageUrls,
videoUrls,
audioUrls,
platforms: platforms?.length ? platforms : undefined,
draftType,
})
if (res?.code !== 0)
throw new Error(res?.message || 'Failed to create generation task')
return {
modelType,
resolution,
duration: resolvedDuration,
aspectRatio: resolvedAspectRatio,
taskIds: res.data?.taskIds || [],
}
}),
)
const fulfilled = results.filter(result => result.status === 'fulfilled')
const placeholders = results.flatMap((result) => {
if (result.status !== 'fulfilled')
return []
return result.value.taskIds.map((id: string) => buildDraftGenerationTaskPlaceholder(id, {
groupId,
model: result.value.modelType,View on GitHub (pinned to d3aa8bea5b)
Solutions
- Inspect the actual res.code/res.message in the network tab to identify the backend cause (401 vs quota vs validation).
- Refresh auth: re-login so the API returns code 0; 401-style codes are the most common trigger.
- Validate request params before calling: ensure audioUrls is a non-empty array of valid URLs and draftType matches the endpoint's expectation.
- Check account generation quota/credits on the backend if codes indicate limits.
- Improve the fallback: surface res.message and code in the thrown error/UI instead of only the generic string.
Example fix
// before
if (res?.code !== 0)
throw new Error(res?.message || 'Failed to create generation task')
// after
if (res?.code !== 0)
throw new Error(`[${res?.code}] ${res?.message || 'Failed to create generation task'}`) Defensive patterns
Strategy: validation
Validate before calling
const params = { audioUrls, platforms, draftType }
if (!audioUrls?.length) throw new Error('audioUrls is required')
if (!draftType) throw new Error('draftType is required')
// then check auth before calling
const authed = await ensureSessionValid() // re-login if expired Type guard
interface ApiEnvelope<T> { code: number; message?: string; data?: T }
function isApiSuccess<T>(res: ApiEnvelope<T> | undefined | null): res is ApiEnvelope<T> & { code: 0 } {
return !!res && res.code === 0
} Try / catch
try {
await createVideoTask(payload)
}
catch (e) {
if (String(e.message).includes('401') || sessionExpired) return redirectToLogin()
toast.error(e.message || '创建生成任务失败')
} Prevention
- Always check code === 0 before using res.data (project API convention)
- Validate audioUrls/platforms/draftType against the endpoint contract before submit
- Refresh tokens proactively; 401-style codes are the top trigger
- Include res.code in thrown errors for actionable debugging
- Check generation quota before enabling the generate button
When it happens
Trigger: Invoking the video generation action in planDetailStore where the create-task API returns { code: non-zero }, e.g. insufficient credits, invalid audioUrls/platforms/draftType params, expired token, or a malformed/empty response (message undefined falls back to the literal string).
Common situations: User submits AI video generation from a draft with an expired session; backend quota exhausted; model parameters (duration/aspectRatio/resolution) rejected; API gateway returns an error envelope without a message field.
Related errors
- body.code
- AiCallFailed
- ChannelPlatformApiFailed
- 解析后的数据为空
- 解析响应数据失败: ${err instanceof Error ? err.message : String(err)
AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31).
Data as JSON: /api/errors/a271b2d5aaf891b2.
Report an issue: GitHub.