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,6 +188,20 @@ public class Session {
// TODO: download client that matches server version
} catch (CannotConnectException ex) {
if (!canceled) {
handleCannotConnectException(ex);
}
} catch (Throwable t) {
logger.fatal("Unable to connect to server - ", t);
if (!canceled) {
disconnect(false);
client.showMessage("Unable to connect to server. " + t.getMessage());
}
}
return false;
}
private void handleCannotConnectException(CannotConnectException ex) {
logger.warn("Cannot connect", ex);
Throwable t = ex.getCause();
String message = "";
while (t != null) {
@ -198,19 +213,14 @@ public class Session {
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);
}
} catch (Throwable t) {
logger.fatal("Unable to connect to server - ", t);
if (!canceled) {
disconnect(false);
client.showMessage("Unable to connect to server. " + t.getMessage());
}
}
return false;
}
public synchronized void disconnect(boolean showMessage) {
if (isConnected())