Skip to content

Commit

Permalink
[LO extension] solves an error in AiRemote
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKruse committed Jun 25, 2024
1 parent 4e4470a commit 378ae7a
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ HttpURLConnection getConnection(byte[] postData, URL url) throws RuntimeExceptio
}
}

public String runInstruction(String instruction, String text, Locale locale, boolean onlyOneParagraph) throws Throwable {
public String runInstruction(String instruction, String text, Locale locale, boolean onlyOneParagraph) {
if (instruction == null || text == null) {
return "";
return null;
}
instruction = instruction.trim();
text = text.trim();
if (onlyOneParagraph && (instruction.isEmpty() || text.isEmpty())) {
return "";
}
if (instruction.isEmpty()) {
if (text.isEmpty()) {
return text;
Expand All @@ -144,9 +147,10 @@ public String runInstruction(String instruction, String text, Locale locale, boo
}
// String langName = getLanguageName(locale);
String langName = locale.Language;
String org = text;
text = text.replace("\n", "\r").replace("\r", " ").replace("\"", "\\\"");

String org = text == null ? instruction : text;
if (text != null) {
text = text.replace("\n", "\r").replace("\r", " ").replace("\"", "\\\"");
}
String urlParameters;
// instruction = addLanguageName(instruction, locale);
if (aiType == AiType.CHAT) {
Expand Down Expand Up @@ -178,7 +182,8 @@ public String runInstruction(String instruction, String text, Locale locale, boo
try {
checkUrl = new URL(url);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
MessageHandler.showError(e);
return null;
}
if (debugMode) {
MessageHandler.printToLogFile("AiRemote: runInstruction: postData: " + urlParameters);
Expand All @@ -202,16 +207,18 @@ public String runInstruction(String instruction, String text, Locale locale, boo
} else {
try (InputStream inputStream = conn.getErrorStream()) {
String error = readStream(inputStream, "utf-8");
throw new RuntimeException("Got error: " + error + " - HTTP response code " + conn.getResponseCode());
MessageHandler.showMessage("Got error: " + error + " - HTTP response code " + conn.getResponseCode());
}
}
} catch (ConnectException e) {
throw new RuntimeException("Could not connect to server at: " + url, e);
MessageHandler.showMessage("Could not connect to server at: " + url);
MessageHandler.showError(e);
} catch (Exception e) {
throw new RuntimeException(e);
MessageHandler.showError(e);
} finally {
conn.disconnect();
}
return null;
}

private String removeSurroundingBrackets(String out, String org) {
Expand Down

0 comments on commit 378ae7a

Please sign in to comment.