fix(ecommerce): handle 402 Payment Required — stop rendering loop and show balance warning

When the server returns 402 (balance insufficient), the rendering loop
continued submitting all remaining scenes, each failing with the same 402.
Now it immediately stops the loop, sets a clear "余额不足,请充值后再生成视频"
error message, and aborts further scene submissions.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 19:42:20 +08:00
parent 5fcd225825
commit 3f19829126
@@ -18,6 +18,7 @@ import {
type PlanStep, type PlanStep,
} from "./ecommerceVideoTypes"; } from "./ecommerceVideoTypes";
import type { AdVideoUserConfig } from "../../api/adVideoPlanClient"; import type { AdVideoUserConfig } from "../../api/adVideoPlanClient";
import { ServerRequestError } from "../../api/serverConnection";
import { saveToolResultToLocal, addToolResultToAssetLibrary } from "../workbench/toolResultActions"; import { saveToolResultToLocal, addToolResultToAssetLibrary } from "../workbench/toolResultActions";
import { useAppStore } from "../../stores"; import { useAppStore } from "../../stores";
@@ -192,8 +193,15 @@ export default function EcommerceVideoWorkspace({
renderAbortRef.current, renderAbortRef.current,
); );
} catch (err) { } catch (err) {
const message = err instanceof Error ? err.message : "生成失败";
const isPaymentError = err instanceof ServerRequestError && err.status === 402;
setScenes((prev) => prev.map((s) => setScenes((prev) => prev.map((s) =>
s.sceneId === scene.sceneId ? { ...s, status: "failed", error: err instanceof Error ? err.message : "生成失败" } : s)); s.sceneId === scene.sceneId ? { ...s, status: "failed", error: isPaymentError ? "余额不足,请充值后继续" : message } : s));
if (isPaymentError) {
setError("余额不足,请充值后再生成视频");
renderAbortRef.current.current = true;
break;
}
} }
} }
setScenes((current) => { setScenes((current) => {