Open source CapCut alternative.
TypeScript
fix(site): surface the provider's real failure reason on Cut generations
David Leb2504333d60a
diff --git a/site/src/cut/lib/generate.ts b/site/src/cut/lib/generate.tsindex 364c66d2..e374959a 100644--- a/site/src/cut/lib/generate.ts+++ b/site/src/cut/lib/generate.ts@@ -140,11 +140,20 @@ async function readError(res: Response, fallback: string): Promise<string> {const body = (await res.json().catch(() => null)) as {error?: unknown;message?: unknown;+ details?: { message?: unknown } | null;} | null;const message = [body?.message, body?.error].find((v): v is string => typeof v === "string" && v.length > 0);if (res.status === 402) return message ?? "Not enough Donkey credits — top up to generate.";+ // The provider tucks the real reason (a safety block, a rejected prompt) under+ // details.message; the top-level message is only a generic headline. Append it so a+ // failure explains itself instead of stopping at "…generation failed."+ const detail =+ typeof body?.details?.message === "string" && body.details.message.trim()+ ? body.details.message.trim()+ : null;+ if (detail && detail !== message) return message ? `${message} ${detail}` : detail;return message ?? fallback;}diff --git a/site/src/lib/inference/adapters/gemini-client.ts b/site/src/lib/inference/adapters/gemini-client.tsindex f33d4b6d..75211675 100644--- a/site/src/lib/inference/adapters/gemini-client.ts+++ b/site/src/lib/inference/adapters/gemini-client.ts@@ -139,7 +139,7 @@ export function geminiApiError(message: string, error: unknown): InferenceProvidreturn new InferenceProviderError(message, {statusCode: status,code: "provider_error",- details: { status: error.status, message: error.message },+ details: { status: error.status, message: humanApiMessage(error.message) },});}@@ -148,6 +148,26 @@ export function geminiApiError(message: string, error: unknown): InferenceProvid});}+// Vertex wraps the human reason in a JSON body ({"error":{"message":"…"}}) and the SDK+// hands the whole blob back as error.message — sometimes behind a "got status: …" prefix.+// Pull the sentence out so callers surface a clean reason, not raw JSON.+function humanApiMessage(raw: string): string {+ const brace = raw.indexOf("{");+ if (brace >= 0) {+ try {+ const parsed = toJsonValue(JSON.parse(raw.slice(brace)));+ if (isJsonObject(parsed)) {+ const err = parsed.error;+ const nested = isJsonObject(err) ? stringValue(err.message) : undefined;+ return nested ?? stringValue(parsed.message) ?? raw.trim();+ }+ } catch {+ // Not JSON after all — fall through to the raw string.+ }+ }+ return raw.trim();+}+// The candidate objects of a generateContent response, and the content parts of one candidate. Both// Gemini adapters (text/Responses and image) walk this same candidates → content.parts structure, so// the traversal lives here once.