Skip to content

Commit

Permalink
Add loop for getword 3 times if fail
Browse files Browse the repository at this point in the history
1. add default return value
2. limit 3 times getting words
  • Loading branch information
zihanltesla committed May 19, 2024
1 parent a88bd3b commit e784b34
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/ch/uzh/ifi/hase/soprafs24/service/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,18 @@ public Room createRoom(Room newRoom) {
// Async fetch words for the theme while creating the room
CompletableFuture<List<String>> wordsFuture = CompletableFuture.supplyAsync(() -> {
try {
return getWords(theme);
List<String> words;
int retryCount = 0;
while (true) {
words = getWords(theme);
if(words != null){
return words;
}
retryCount++;
if (retryCount >= 3) {
return new ArrayList<>(Arrays.asList("sopra", "group", "milestone", "sprint", "task", "client", "server"));
}
}
} catch (IOException e) {
System.err.println("Error while getting words: " + e.getMessage());
throw new RuntimeException(e);
Expand Down Expand Up @@ -208,7 +219,7 @@ public List<String> getWords(String theme) throws IOException {
throw new IOException("Failed to extract JSON from message content");
}
} catch (Exception e) {
e.printStackTrace();
// e.printStackTrace();
throw new IOException("Failed to parse JSON response", e);
}
} else {
Expand Down

0 comments on commit e784b34

Please sign in to comment.