1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-09 17:00:09 -09:00

another improvement to cannot connect message

This commit is contained in:
BetaSteward 2011-11-04 22:53:40 -04:00
parent 0b19f91ffd
commit 550ad2bc69

View file

@ -33,6 +33,7 @@ import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@ -187,20 +188,7 @@ public class Session {
// TODO: download client that matches server version
} catch (CannotConnectException ex) {
if (!canceled) {
Throwable t = ex.getCause();
String message = "";
while (t != null) {
if (t instanceof ConnectException) {
message = "Server is likely offline.";
break;
}
if (t instanceof SocketException) {
message = "Check your internet connection.";
break;
}
t = t.getCause();
}
client.showMessage("Unable to connect to server. " + message);
handleCannotConnectException(ex);
}
} catch (Throwable t) {
logger.fatal("Unable to connect to server - ", t);
@ -212,6 +200,28 @@ public class Session {
return false;
}
private void handleCannotConnectException(CannotConnectException ex) {
logger.warn("Cannot connect", ex);
Throwable t = ex.getCause();
String message = "";
while (t != null) {
if (t instanceof ConnectException) {
message = "Server is likely offline.";
break;
}
if (t instanceof SocketException) {
message = "Check your internet connection.";
break;
}
if (t instanceof SocketTimeoutException) {
message = "Server is not responding.";
break;
}
t = t.getCause();
}
client.showMessage("Unable to connect to server. " + message);
}
public synchronized void disconnect(boolean showMessage) {
if (isConnected())
sessionState = SessionState.DISCONNECTING;