Catch the error

This commit is contained in:
Lim Chee Aun 2023-04-27 18:12:38 +08:00
parent 2ed6b80dcc
commit 23057efcca

View file

@ -54,6 +54,7 @@ function TranslationBlock({
const translate = async () => { const translate = async () => {
setUIState('loading'); setUIState('loading');
try {
const { content, detectedSourceLanguage, provider, ...props } = const { content, detectedSourceLanguage, provider, ...props } =
await onTranslate(apiSourceLang.current, targetLang); await onTranslate(apiSourceLang.current, targetLang);
if (content) { if (content) {
@ -78,6 +79,10 @@ function TranslationBlock({
console.error(result); console.error(result);
setUIState('error'); setUIState('error');
} }
} catch (e) {
console.error(e);
setUIState('error');
}
}; };
useEffect(() => { useEffect(() => {