Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) {
.filter(this::isAttachmentRelevant)
.toList();

if (attachments.isEmpty()) {
return;
}

CompletableFuture.runAsync(() -> {
try {
processAttachments(event, attachments);
} catch (Exception e) {
LOGGER.error("Unknown error while processing attachments", e);
LOGGER.error(
"Unknown error while processing attachments. Channel: {}, Author: {}, Message ID: {}.",
event.getChannel().getName(), author.getId(), event.getMessageId(), e);
}
});
}
Expand Down Expand Up @@ -120,7 +126,7 @@ private void processAttachments(@NotNull MessageReceivedEvent event,
}

private @NotNull String readAttachment(@NotNull InputStream stream) {
try {
try (stream) {
return new String(stream.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down Expand Up @@ -179,7 +185,8 @@ private void processAttachments(@NotNull MessageReceivedEvent event,

if (statusCode < HttpURLConnection.HTTP_OK
|| statusCode >= HttpURLConnection.HTTP_MULT_CHOICE) {
throw new IllegalStateException("Gist API unexpected response: " + apiResponse.body());
throw new IllegalStateException("Gist API unexpected response: %s. Request JSON: %s"
.formatted(apiResponse.body(), body));
}

GistResponse gistResponse;
Expand Down