diff --git a/src/main/java/it/ohalee/minecraftgpt/OpenAI.java b/src/main/java/it/ohalee/minecraftgpt/OpenAI.java index f135129..8c308f0 100644 --- a/src/main/java/it/ohalee/minecraftgpt/OpenAI.java +++ b/src/main/java/it/ohalee/minecraftgpt/OpenAI.java @@ -31,12 +31,13 @@ public class OpenAI { .build()) .getChoices().get(0).getText()).exceptionally(throwable -> { if (throwable.getCause() instanceof HttpException e) { - return switch (e.response().code()) { + String reason = switch (e.response().code()) { case 401 -> "Invalid API key! Please check your configuration."; case 429 -> "Too many requests! Please wait a few seconds and try again."; case 500 -> "OpenAI service is currently unavailable. Please try again later."; default -> "Unknown error! Please try again later. If this error persists, contact the plugin developer."; }; + throw new RuntimeException(reason, throwable); } throw new RuntimeException(throwable); }); diff --git a/src/main/java/it/ohalee/minecraftgpt/handler/PlayerHandlers.java b/src/main/java/it/ohalee/minecraftgpt/handler/PlayerHandlers.java index 693e56e..c9effc4 100644 --- a/src/main/java/it/ohalee/minecraftgpt/handler/PlayerHandlers.java +++ b/src/main/java/it/ohalee/minecraftgpt/handler/PlayerHandlers.java @@ -52,7 +52,7 @@ public class PlayerHandlers implements Listener { if (builder == null) builder = new StringBuilder(); OpenAI.getResponse(plugin.getConfig().getConfigurationSection("chatgpt"), builder, e.getMessage()).whenComplete((response, throwable) -> { - if (response == null) { + if (throwable != null) { player.sendMessage(Messages.format(plugin.getConfig().getString("command.error"))); return; }