Improve generation task client errors

This commit is contained in:
2026-06-04 21:07:48 +08:00
parent 8fbb2ec95e
commit d36a093159
3 changed files with 8 additions and 7 deletions
+5 -4
View File
@@ -54,15 +54,13 @@ export function waitForTask(
if (event.status === "completed") {
settle(() => resolve(event.resultUrl || null));
} else if (event.status === "failed" || event.status === "cancelled") {
settle(() => reject(new Error(event.error || "任务失败")));
settle(() => reject(new Error(event.error || "任务失败,请稍后重试")));
}
};
// Try SSE first
cleanup = aiGenerationClient.subscribeTaskStatus(taskId, handleUpdate);
sseConnected = true;
// Fallback: if SSE doesn't deliver any event within 5s, switch to polling
fallbackTimerId = setTimeout(() => {
if (settled || !sseConnected) return;
if (cleanup) cleanup();
@@ -72,7 +70,10 @@ export function waitForTask(
function startPolling() {
const poll = async () => {
while (!settled) {
if (abortRef?.current) { settle(() => resolve(null)); return; }
if (abortRef?.current) {
settle(() => resolve(null));
return;
}
await new Promise((r) => setTimeout(r, POLL_INTERVAL));
if (settled || abortRef?.current) return;
try {