fix(translate): do not pretend there is a page source if the connection fails
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2024-05-11 17:36:04 +02:00
parent fe2808cf45
commit 3bc7df7089
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 6 additions and 2 deletions

View File

@ -49,9 +49,13 @@ public class GoogleTranslateService extends AbstractTranslateService<GoogleTrans
@Override
protected String performTranslate(String textToTranslate, GoogleTranslateLanguage translateFrom, GoogleTranslateLanguage translateTo) throws Exception {
String pageSource = "";
String pageSource;
try {
pageSource = getPageSource(textToTranslate, translateFrom.getIdentifier(), translateTo.getIdentifier());
} catch (Exception e) {
throw new TranslateException("Could not translate string", e);
}
try {
Matcher matcher = TRANSLATION_RESULT.matcher(pageSource);
if (matcher.find()) {
String match = matcher.group(1);
@ -62,7 +66,7 @@ public class GoogleTranslateService extends AbstractTranslateService<GoogleTrans
throw new TranslateException("Could not translate \"" + textToTranslate + "\": result page couldn't be parsed");
} catch (Exception e) {
try {
Path p = Files.createTempFile("translater-pagedump-", ".html").toAbsolutePath();
Path p = Files.createTempFile("libjf-translate-pagedump-", ".html").toAbsolutePath();
Files.writeString(p, pageSource);
throw new TranslateException("Could not translate string, see dumped page at " + p, e);
} catch (IOException ioe) {