From 5741d47770f8af87e4e53706a2ec16b823fcbf16 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Thu, 16 Feb 2023 13:12:04 +0100 Subject: [PATCH] Improved error handling when connecting --- .../viaproxy/proxy/client2proxy/Client2ProxyHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java index 1175a62..ac57b9b 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -56,6 +56,7 @@ import net.raphimc.viaproxy.util.logging.Logger; import javax.crypto.SecretKey; import java.math.BigInteger; +import java.net.ConnectException; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.KeyPair; @@ -219,7 +220,12 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { this.proxyConnection.getChannel().writeAndFlush(new C2SHandshakePacket(clientVersion.getOriginalVersion(), serverAddress.getAddress(), serverAddress.getPort(), packet.intendedState)).await().addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); this.proxyConnection.setConnectionState(packet.intendedState); } catch (Throwable e) { - this.proxyConnection.kickClient("§cCould not connect to the backend server!\n§cTry again in a few seconds."); + if (e instanceof ConnectException) { // Trust me, this is not always false + this.proxyConnection.kickClient("§cCould not connect to the backend server!\n§cTry again in a few seconds."); + } else { + Logger.LOGGER.error("Error while connecting to the backend server", e); + this.proxyConnection.kickClient("§cAn error occurred while connecting to the backend server: " + e.getMessage() + "\n§cCheck the console for more information."); + } } }