Better error handling for image desc generator

400 doesn't throw error
This commit is contained in:
Lim Chee Aun 2024-01-06 12:23:15 +08:00
parent 9cffd429b0
commit 7223baaaad

View file

@ -1838,10 +1838,17 @@ function MediaAttachment({
method: 'POST',
body,
}).then((r) => r.json());
if (response.error) {
throw new Error(response.error);
}
setDescription(response.description);
} catch (e) {
console.error(e);
showToast('Failed to generate description');
showToast(
`Failed to generate description${
e?.message ? `: ${e.message}` : ''
}`,
);
} finally {
setUIState('default');
toastRef.current?.hideToast?.();