Skip to content

Commit

Permalink
fix http timeout being too long
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Dec 12, 2024
1 parent 8e14293 commit 2ea9f70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/vc/api/VcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ApiClient apiClientChats(
@Value("${API_KEY}") final String apiKey
) {
return apiClient(httpClientBuilder, objectMapper, apiKey)
.setReadTimeout(Duration.ofSeconds(90));
.setReadTimeout(Duration.ofSeconds(60));
}

@Bean
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/vc/listeners/SlashCommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public Mono<Message> handleChatInteraction(ChatInputInteractionEvent event) {
return event.reply("Command not found").dematerialize();
}
return event.deferReply()
.doOnSuccess(msg -> logMessage(command, event, beforeTime))
.then(Mono.defer(() -> command.handle(event)))
.doOnError(e -> LOGGER.error("Error handling command", e));
.doOnSuccess(msg -> logMessage(command, event, beforeTime, null))
.doOnError(e -> logMessage(command, event, beforeTime, e));
}

public Mono<Message> handleButtonInteraction(ButtonInteractionEvent event) {
Expand All @@ -60,12 +60,12 @@ public Mono<Message> handleButtonInteraction(ButtonInteractionEvent event) {
return event.reply("Button handler not found for id: " + event.getCustomId()).dematerialize();
}
return event.deferReply()
.doOnSuccess(v -> logButton(event, beforeTime))
.then(Mono.defer(() -> listener.handleButton(event)))
.doOnError(e -> LOGGER.error("Error handling button", e));
.doOnSuccess(v -> logButton(event, beforeTime, null))
.doOnError(e -> logButton(event, beforeTime, e));
}

private void logButton(final ButtonInteractionEvent event, final Instant beforeTime) {
private void logButton(final ButtonInteractionEvent event, final Instant beforeTime, final Throwable error) {
try {
Instant afterTime = Instant.now();
String username = event.getInteraction().getUser().getTag();
Expand All @@ -79,12 +79,15 @@ private void logButton(final ButtonInteractionEvent event, final Instant beforeT
username,
guild,
event.getCustomId());
if (error != null) {
LOGGER.error("Error handling button", error);
}
} catch (final Exception e) {
LOGGER.warn("failed logging button", e);
}
}

private void logMessage(SlashCommand command, final ChatInputInteractionEvent event, final Instant beforeTime) {
private void logMessage(SlashCommand command, final ChatInputInteractionEvent event, final Instant beforeTime, Throwable error) {
try {
Instant afterTime = Instant.now();
String username = event.getInteraction().getUser().getTag();
Expand All @@ -106,6 +109,9 @@ private void logMessage(SlashCommand command, final ChatInputInteractionEvent ev
guild,
command.getName(),
!dataOptions.isEmpty() ? " : " + dataOptions : "");
if (error != null) {
LOGGER.error("Error executing command", error);
}
} catch (final Exception e) {
LOGGER.warn("failed logging command", e);
}
Expand Down

0 comments on commit 2ea9f70

Please sign in to comment.