mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-01-23 09:06:23 +01:00
Catch the error
This commit is contained in:
parent
2ed6b80dcc
commit
23057efcca
1 changed files with 25 additions and 20 deletions
|
@ -54,28 +54,33 @@ function TranslationBlock({
|
||||||
|
|
||||||
const translate = async () => {
|
const translate = async () => {
|
||||||
setUIState('loading');
|
setUIState('loading');
|
||||||
const { content, detectedSourceLanguage, provider, ...props } =
|
try {
|
||||||
await onTranslate(apiSourceLang.current, targetLang);
|
const { content, detectedSourceLanguage, provider, ...props } =
|
||||||
if (content) {
|
await onTranslate(apiSourceLang.current, targetLang);
|
||||||
if (detectedSourceLanguage) {
|
if (content) {
|
||||||
const detectedLangText = localeCode2Text(detectedSourceLanguage);
|
if (detectedSourceLanguage) {
|
||||||
setDetectedLang(detectedLangText);
|
const detectedLangText = localeCode2Text(detectedSourceLanguage);
|
||||||
}
|
setDetectedLang(detectedLangText);
|
||||||
if (provider === 'lingva') {
|
|
||||||
const pronunciation = props?.info?.pronunciation?.query;
|
|
||||||
if (pronunciation) {
|
|
||||||
setPronunciationContent(pronunciation);
|
|
||||||
}
|
}
|
||||||
|
if (provider === 'lingva') {
|
||||||
|
const pronunciation = props?.info?.pronunciation?.query;
|
||||||
|
if (pronunciation) {
|
||||||
|
setPronunciationContent(pronunciation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTranslatedContent(content);
|
||||||
|
setUIState('default');
|
||||||
|
detailsRef.current.open = true;
|
||||||
|
detailsRef.current.scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
block: 'nearest',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error(result);
|
||||||
|
setUIState('error');
|
||||||
}
|
}
|
||||||
setTranslatedContent(content);
|
} catch (e) {
|
||||||
setUIState('default');
|
console.error(e);
|
||||||
detailsRef.current.open = true;
|
|
||||||
detailsRef.current.scrollIntoView({
|
|
||||||
behavior: 'smooth',
|
|
||||||
block: 'nearest',
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.error(result);
|
|
||||||
setUIState('error');
|
setUIState('error');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue