Browse Source

fix: handle Kie API errors returned with HTTP 200

Kie API returns HTTP 200 even on errors, with error code in the JSON body.
Now properly checks createResult.code !== 200 and returns the actual error
message from the API instead of generic "No task ID in response".

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
handoff-20260429-1057
lapoaiscalers 6 months ago
parent
commit
b8bb8a9942
  1. 11
      src/app/api/generate/route.ts

11
src/app/api/generate/route.ts

@ -1632,6 +1632,17 @@ async function generateWithKie(
}
const createResult = await createResponse.json();
// Kie API returns HTTP 200 even on errors, check the response code
if (createResult.code && createResult.code !== 200) {
const errorMsg = createResult.msg || createResult.message || "API error";
console.error(`[API:${requestId}] Kie API error (code ${createResult.code}):`, errorMsg);
return {
success: false,
error: `${input.model.name}: ${errorMsg}`,
};
}
const taskId = createResult.taskId || createResult.data?.taskId || createResult.id;
if (!taskId) {

Loading…
Cancel
Save