add try catch alert to imageGen

This commit is contained in:
2023-11-10 22:14:47 +08:00
parent bd6edb4ca8
commit a72e98ad25

View File

@@ -195,6 +195,7 @@ export function AddImage({
className="bg-sky-400 m-1 p-1 rounded disabled:bg-slate-500" className="bg-sky-400 m-1 p-1 rounded disabled:bg-slate-500"
disabled={imageGenGenerating} disabled={imageGenGenerating}
onClick={async () => { onClick={async () => {
try {
setImageGenGenerating(true); setImageGenGenerating(true);
const body: any = { const body: any = {
prompt: imageGenPrompt, prompt: imageGenPrompt,
@@ -217,6 +218,7 @@ export function AddImage({
body: JSON.stringify(body), body: JSON.stringify(body),
}).then((resp) => resp.json()) }).then((resp) => resp.json())
).data; ).data;
console.log("image gen resp", resp);
for (const image of resp) { for (const image of resp) {
let url = ""; let url = "";
@@ -247,9 +249,12 @@ export function AddImage({
setChatStore({ ...chatStore }); setChatStore({ ...chatStore });
} }
} catch (e) {
console.error(e);
alert("Failed to generate image: " + e);
} finally {
setImageGenGenerating(false); setImageGenGenerating(false);
console.log("image resp", resp); }
}} }}
> >
{Tr("Generate")} {Tr("Generate")}