fix(translate): do not pretend there is a page source if the connection fails
This commit is contained in:
parent
fe2808cf45
commit
3bc7df7089
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue