Skip to content

Commit 09af435

Browse files
committed
Do exception handling self and in whenComplete for better semantics and correct logging category
1 parent b69d7b8 commit 09af435

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/main/java/net/kautler/command/api/CommandHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ private boolean isCommandAllowed(M message, Command<? super M> command) {
350350
*/
351351
protected void executeAsync(M message, Runnable commandExecutor) {
352352
runAsync(commandExecutor, getExecutorService())
353-
.exceptionally(throwable -> {
354-
logger.error("Exception while executing command asynchronously", throwable);
355-
return null;
353+
.whenComplete((result, throwable) -> {
354+
if (throwable != null) {
355+
logger.error("Exception while executing command asynchronously", throwable);
356+
}
356357
});
357358
}
358359

src/main/java/net/kautler/command/handler/CommandHandlerJavacord.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.javacord.api.DiscordApi;
2828
import org.javacord.api.entity.message.Message;
2929
import org.javacord.api.event.message.MessageCreateEvent;
30-
import org.javacord.api.util.logging.ExceptionLogger;
3130

3231
import javax.annotation.PostConstruct;
3332
import javax.enterprise.context.ApplicationScoped;
@@ -159,6 +158,10 @@ protected void fireCommandNotFoundEvent(Message message, String prefix, String u
159158
@Override
160159
protected void executeAsync(Message message, Runnable commandExecutor) {
161160
runAsync(commandExecutor, message.getApi().getThreadPool().getExecutorService())
162-
.exceptionally(ExceptionLogger.get());
161+
.whenComplete((result, throwable) -> {
162+
if (throwable != null) {
163+
logger.error("Exception while executing command asynchronously", throwable);
164+
}
165+
});
163166
}
164167
}

0 commit comments

Comments
 (0)