fix: translation results may not be returned

This commit is contained in:
Vincent Yang 2024-04-09 03:02:37 -04:00
parent f75bfc20f7
commit 7b97e65ec7
No known key found for this signature in database
GPG Key ID: 55F1635E821BF0E8

View File

@ -2,7 +2,7 @@
* @Author: Vincent Yang
* @Date: 2023-07-01 21:45:34
* @LastEditors: Vincent Yang
* @LastEditTime: 2024-03-20 16:39:58
* @LastEditTime: 2024-04-09 03:02:08
* @FilePath: /DeepLX/main.go
* @Telegram: https://t.me/missuo
* @GitHub: https://github.com/missuo
@ -314,6 +314,12 @@ func translateByDeepLX(sourceLang string, targetLang string, translateText strin
alternatives = append(alternatives, value.Get("text").String())
return true
})
if res.Get("result.texts.0.text").String() == "" {
return DeepLXTranslationResult{
Code: http.StatusServiceUnavailable,
Message: "Translation failed, API returns an empty result.",
}, nil
} else {
return DeepLXTranslationResult{
Code: http.StatusOK,
ID: id,
@ -325,6 +331,7 @@ func translateByDeepLX(sourceLang string, targetLang string, translateText strin
Method: "Free",
}, nil
}
}
return DeepLXTranslationResult{
Code: http.StatusServiceUnavailable,
Message: "Uknown error",