mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-22 09:15:33 +03: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 () => {
|
||||
setUIState('loading');
|
||||
const { content, detectedSourceLanguage, provider, ...props } =
|
||||
await onTranslate(apiSourceLang.current, targetLang);
|
||||
if (content) {
|
||||
if (detectedSourceLanguage) {
|
||||
const detectedLangText = localeCode2Text(detectedSourceLanguage);
|
||||
setDetectedLang(detectedLangText);
|
||||
}
|
||||
if (provider === 'lingva') {
|
||||
const pronunciation = props?.info?.pronunciation?.query;
|
||||
if (pronunciation) {
|
||||
setPronunciationContent(pronunciation);
|
||||
try {
|
||||
const { content, detectedSourceLanguage, provider, ...props } =
|
||||
await onTranslate(apiSourceLang.current, targetLang);
|
||||
if (content) {
|
||||
if (detectedSourceLanguage) {
|
||||
const detectedLangText = localeCode2Text(detectedSourceLanguage);
|
||||
setDetectedLang(detectedLangText);
|
||||
}
|
||||
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);
|
||||
setUIState('default');
|
||||
detailsRef.current.open = true;
|
||||
detailsRef.current.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'nearest',
|
||||
});
|
||||
} else {
|
||||
console.error(result);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
setUIState('error');
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue