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

  1. Inspect the actual res.code/res.message in the network tab to identify the backend cause (401 vs quota vs validation).
  2. Refresh auth: re-login so the API returns code 0; 401-style codes are the most common trigger.
  3. Validate request params before calling: ensure audioUrls is a non-empty array of valid URLs and draftType matches the endpoint's expectation.
  4. Check account generation quota/credits on the backend if codes indicate limits.
  5. 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

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


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