mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 20:10:24 +08:00
fix: handle unexpected fal response (#7158)
This commit is contained in:
@@ -26,8 +26,8 @@ const FalImageSchema = z
|
|||||||
url: z.string(),
|
url: z.string(),
|
||||||
seed: z.number().optional(),
|
seed: z.number().optional(),
|
||||||
content_type: z.string(),
|
content_type: z.string(),
|
||||||
file_name: z.string(),
|
file_name: z.string().optional(),
|
||||||
file_size: z.number(),
|
file_size: z.number().optional(),
|
||||||
width: z.number(),
|
width: z.number(),
|
||||||
height: z.number(),
|
height: z.number(),
|
||||||
})
|
})
|
||||||
@@ -200,8 +200,10 @@ export class FalProvider
|
|||||||
if (model.startsWith('workflows/')) {
|
if (model.startsWith('workflows/')) {
|
||||||
const stream = await falStream(model, { input: prompt });
|
const stream = await falStream(model, { input: prompt });
|
||||||
|
|
||||||
const result = FalStreamOutputSchema.parse(await stream.done());
|
const result = FalStreamOutputSchema.safeParse(await stream.done());
|
||||||
return result.output;
|
if (result.success) return result.data.output;
|
||||||
|
const errors = JSON.stringify(result.error.errors);
|
||||||
|
throw new Error(`Unexpected fal response: ${errors}`);
|
||||||
} else {
|
} else {
|
||||||
const response = await fetch(`https://fal.run/fal-ai/${model}`, {
|
const response = await fetch(`https://fal.run/fal-ai/${model}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -217,7 +219,10 @@ export class FalProvider
|
|||||||
}),
|
}),
|
||||||
signal: options.signal,
|
signal: options.signal,
|
||||||
});
|
});
|
||||||
return FalResponseSchema.parse(await response.json());
|
const result = FalResponseSchema.safeParse(await response.json());
|
||||||
|
if (result.success) return result.data;
|
||||||
|
const errors = JSON.stringify(result.error.errors);
|
||||||
|
throw new Error(`Unexpected fal response: ${errors}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user