Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not printing reconnect-event as error #674

Merged
merged 1 commit into from Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -33,6 +33,7 @@
import discord4j.gateway.retry.GatewayException;
import discord4j.gateway.retry.GatewayStateChange;
import discord4j.gateway.retry.PartialDisconnectException;
import discord4j.gateway.retry.ReconnectException;
import io.netty.buffer.ByteBuf;
import org.reactivestreams.Publisher;
import reactor.core.publisher.*;
Expand Down Expand Up @@ -259,7 +260,13 @@ public Mono<Void> execute(String gatewayUrl) {
.then();

return Mono.zip(httpFuture, readyHandler, receiverFuture, senderFuture, heartbeatHandler)
.doOnError(t -> log.error(format(context, "{}"), t.toString()))
.doOnError(t -> {
if(t instanceof ReconnectException) {
log.info(format(context, "{}"), t.getMessage());
} else {
log.error(format(context, "{}"), t.toString());
}
})
.doOnTerminate(heartbeat::stop)
.doOnCancel(() -> sessionHandler.close())
.then();
Expand Down
Expand Up @@ -20,6 +20,7 @@
import discord4j.common.close.DisconnectBehavior;
import discord4j.gateway.retry.GatewayException;
import discord4j.gateway.retry.PartialDisconnectException;
import discord4j.gateway.retry.ReconnectException;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
Expand Down Expand Up @@ -150,7 +151,9 @@ public void close(DisconnectBehavior behavior) {
* @param error the cause for this session termination
*/
public void error(Throwable error) {
log.info(format(context, "Triggering error sequence: {}"), error.toString());
if (!(error instanceof ReconnectException)) {
log.info(format(context, "Triggering error sequence: {}"), error.toString());
}
close(DisconnectBehavior.retryAbruptly(error));
}
}
11 changes: 7 additions & 4 deletions gateway/src/main/java/discord4j/gateway/PayloadHandlers.java
Expand Up @@ -18,8 +18,9 @@

import discord4j.discordjson.json.gateway.*;
import discord4j.discordjson.possible.Possible;
import discord4j.gateway.json.*;
import discord4j.gateway.json.GatewayPayload;
import discord4j.gateway.retry.GatewayException;
import discord4j.gateway.retry.ReconnectException;
import reactor.util.Logger;
import reactor.util.Loggers;

Expand Down Expand Up @@ -81,7 +82,7 @@ private static void handleHeartbeat(PayloadContext<Heartbeat> context) {
}

private static void handleReconnect(PayloadContext<?> context) {
context.getHandler().error(new RuntimeException("Reconnecting due to reconnect packet received"));
context.getHandler().error(new ReconnectException("Reconnecting due to reconnect packet received"));
}

private static void handleInvalidSession(PayloadContext<InvalidSession> context) {
Expand All @@ -107,7 +108,8 @@ private static void handleHello(PayloadContext<Hello> context) {
client.sender().next(GatewayPayload.resume(
ImmutableResume.of(client.token(), client.getSessionId(), client.sequence().get())));
} else {
IdentifyProperties props = ImmutableIdentifyProperties.of(System.getProperty("os.name"), "Discord4J", "Discord4J");
IdentifyProperties props = ImmutableIdentifyProperties.of(System.getProperty("os.name"), "Discord4J",
"Discord4J");
IdentifyOptions options = client.identifyOptions();
int[] shard = new int[]{options.getShardIndex(), options.getShardCount()};
Identify identify = Identify.builder()
Expand All @@ -118,7 +120,8 @@ private static void handleHello(PayloadContext<Hello> context) {
.largeThreshold(250)
.shard(shard)
.presence(Optional.ofNullable(options.getInitialStatus()).map(Possible::of).orElse(Possible.absent()))
.guildSubscriptions(options.getIntents().isAbsent() ? Possible.of(options.isGuildSubscriptions()) : Possible.absent())
.guildSubscriptions(options.getIntents().isAbsent() ?
Possible.of(options.isGuildSubscriptions()) : Possible.absent())
.build();
log.debug(format(context.getContext(), "Identifying to Gateway"), client.sequence().get());
client.sender().next(GatewayPayload.identify(identify));
Expand Down
@@ -0,0 +1,12 @@
package discord4j.gateway.retry;

/**
* An exception class to handle gateway reconnects via reconnect opcode
*/
public class ReconnectException extends RuntimeException {

public ReconnectException(String message) {
super(message);
}
}