[AB-323] improving logging when using whenComplete

This commit is contained in:
Sheldan
2021-08-14 12:15:18 +02:00
parent 3ed1f0c54a
commit 19a4858da1
15 changed files with 88 additions and 52 deletions

View File

@@ -48,12 +48,11 @@ public class WarnEntryConverter {
allFutures.add(warnedMemberFuture);
});
CompletableFuture<List<WarnEntry>> future = new CompletableFuture<>();
FutureUtils.toSingleFutureGeneric(allFutures).whenComplete((unused, throwable) -> {
try {
future.complete(self.loadFullWarnEntries(loadedWarnings));
} catch (Exception exception) {
future.completeExceptionally(exception);
}
FutureUtils.toSingleFutureGeneric(allFutures)
.whenComplete((unused, throwable) -> future.complete(self.loadFullWarnEntries(loadedWarnings)))
.exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
});
return future;
}

View File

@@ -90,6 +90,9 @@ public class BanServiceBean implements BanService {
returningFuture.completeExceptionally(throwable1);
return null;
});
}).exceptionally(throwable -> {
returningFuture.completeExceptionally(throwable);
return null;
});
return returningFuture;
}

View File

@@ -163,6 +163,9 @@ public class MuteServiceBean implements MuteService {
channelService.sendTextToChannel(throwable.getMessage(), feedBackChannel).whenComplete((exceptionMessage, innerThrowable) -> {
notificationFuture.complete(null);
log.info("Successfully notified user {} in server {} about mute.", memberBeingMuted.getId(), memberBeingMuted.getGuild().getId());
}).exceptionally(throwable1 -> {
notificationFuture.completeExceptionally(throwable1);
return null;
});
return null;
});

View File

@@ -155,14 +155,18 @@ public class PurgeServiceBean implements PurgeService {
return aVoid -> {
if (amountToDelete >= 1) {
log.debug("Still more than 1 message to delete. Continuing.");
purgeMessages(amountToDelete, channel, earliestMessage.getIdLong(), purgedMember, totalCount, currentCount, currentStatusMessageId).whenComplete((avoid, throwable) -> {
purgeMessages(amountToDelete, channel, earliestMessage.getIdLong(), purgedMember, totalCount, currentCount, currentStatusMessageId)
.whenComplete((avoid, throwable) -> {
if (throwable != null) {
deletionFuture.completeExceptionally(throwable);
} else {
deletionFuture.complete(null);
}
}
);
).exceptionally(throwable -> {
deletionFuture.completeExceptionally(throwable);
return null;
});
} else {
log.debug("Completed purging of {} messages.", totalCount);
// Todo Move to message service

View File

@@ -195,9 +195,13 @@ public class WarnServiceBean implements WarnService {
log.warn("Could not find user {} in server {}. Not notifying about decayed warning {}.", userId, serverId, warningId);
}
});
CompletableFuture<Void> future = new CompletableFuture();
CompletableFuture<Void> future = new CompletableFuture<>();
FutureUtils.toSingleFutureGeneric(notificationFutures)
.whenComplete((unused, throwable) -> future.complete(null));
.whenComplete((unused, throwable) -> future.complete(null))
.exceptionally(throwable -> {
future.completeExceptionally(throwable);
return null;
});
return future;
}