Browse Source

fix: handle transient poll errors in Kie task polling

The Kie API can return 404/422 or HTTP 200 with non-200 code when
polling starts before the task is fully registered. Previously these
were treated as fatal errors, causing the client to see a network error
even though the generation was still processing on Kie's side. Now
these transient responses are retried instead of aborting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 3 months ago
parent
commit
2049648b5e
  1. 12
      src/app/api/generate/providers/kie.ts

12
src/app/api/generate/providers/kie.ts

@ -417,10 +417,22 @@ export async function pollKieTaskCompletion(
});
if (!response.ok) {
// 404/422 can happen transiently when the task isn't registered yet — retry
if (response.status === 404 || response.status === 422) {
console.log(`[API:${requestId}] Kie poll returned ${response.status}, task not ready yet — retrying`);
continue;
}
return { success: false, error: `Failed to poll status: ${response.status}` };
}
const result = await response.json();
// Kie API can return HTTP 200 with code != 200 (e.g. "recordInfo is null")
if (result.code && result.code !== 200) {
console.log(`[API:${requestId}] Kie poll returned code ${result.code}: ${result.msg || ""} — retrying`);
continue;
}
// Kie API returns "state" in result.data.state (not "status")
const state = (result.data?.state || result.state || result.status || "").toUpperCase();

Loading…
Cancel
Save