Improved error handling

This commit is contained in:
RaphiMC 2023-03-11 12:53:34 +01:00
parent 3cbdc73657
commit 11176c9799

View File

@ -58,6 +58,7 @@ import net.raphimc.viaproxy.util.logging.Logger;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.ConnectException; import java.net.ConnectException;
import java.nio.channels.UnresolvedAddressException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.KeyPair; import java.security.KeyPair;
@ -225,7 +226,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
this.proxyConnection.getChannel().writeAndFlush(new C2SHandshakePacket(clientVersion.getOriginalVersion(), serverAddress.getAddress(), serverAddress.getPort(), packet.intendedState)).await().addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); 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); this.proxyConnection.setConnectionState(packet.intendedState);
} catch (Throwable e) { } catch (Throwable e) {
if (e instanceof ConnectException) { // Trust me, this is not always false if (e instanceof ConnectException || e instanceof UnresolvedAddressException) { // Trust me, this is not always false
this.proxyConnection.kickClient("§cCould not connect to the backend server!\n§cTry again in a few seconds."); this.proxyConnection.kickClient("§cCould not connect to the backend server!\n§cTry again in a few seconds.");
} else { } else {
Logger.LOGGER.error("Error while connecting to the backend server", e); Logger.LOGGER.error("Error while connecting to the backend server", e);