Skip to content

Commit 1b1b29f

Browse files
committed
Separate error messages if incorrect server address or there's no connection
1 parent 91f5656 commit 1b1b29f

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/utilities/BgTask.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import fi.helsinki.cs.tmc.core.exceptions.AuthenticationFailedException;
55
import fi.helsinki.cs.tmc.core.exceptions.NotLoggedInException;
66
import fi.helsinki.cs.tmc.coreimpl.BridgingProgressObserver;
7+
import java.io.IOException;
78

89
import java.util.concurrent.Callable;
910
import java.util.concurrent.Future;
@@ -140,14 +141,14 @@ public void run() {
140141
try {
141142
successful = true;
142143
resultTemp = callable.call();
143-
} catch (NotLoggedInException | OAuthProblemException | OAuthSystemException | AuthenticationFailedException ex) {
144+
} catch (NotLoggedInException | OAuthProblemException | OAuthSystemException | AuthenticationFailedException | IOException ex) {
144145
successful = false;
145146
boolean authenticationSuccessful;
146147
do {
147148
try {
148149
authenticationSuccessful = true;
149150
new LoginManager().login();
150-
} catch (AuthenticationFailedException loginException) {
151+
} catch (AuthenticationFailedException | IOException | InterruptedException exception) {
151152
authenticationSuccessful = false;
152153
}
153154
} while (!authenticationSuccessful);

tmc-plugin/src/fi/helsinki/cs/tmc/utilities/LoginManager.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
import java.awt.event.ActionEvent;
1818
import java.awt.event.ActionListener;
19+
import java.io.FileNotFoundException;
20+
import java.io.IOException;
21+
import java.net.UnknownHostException;
1922
import java.util.logging.Level;
2023
import java.util.logging.Logger;
2124

@@ -26,8 +29,9 @@ public class LoginManager {
2629
private boolean ready;
2730
private Logger log = Logger.getLogger(LoginManager.class.getName());
2831
private AuthenticationFailedException authenticationException;
32+
private IOException connectionException;
2933

30-
public synchronized void login() throws InterruptedException, AuthenticationFailedException {
34+
public synchronized void login() throws InterruptedException, AuthenticationFailedException, IOException {
3135
if (LoginDialog.isWindowVisible() || OrganizationListWindow.isWindowVisible() || CourseListWindow.isWindowVisible()) {
3236
return;
3337
}
@@ -49,6 +53,14 @@ public void actionPerformed(ActionEvent e) {
4953
try {
5054
TmcCore.get().authenticate(ProgressObserver.NULL_OBSERVER, TmcSettingsHolder.get().getPassword().get()).call();
5155
} catch (Exception ex) {
56+
if (ex instanceof IOException) {
57+
connectionException = (IOException)ex;
58+
if (ex instanceof UnknownHostException) {
59+
ConvenientDialogDisplayer.getDefault().displayError("Couldn't connect to the server. Please check your internet connection.");
60+
} else if (ex instanceof FileNotFoundException) {
61+
ConvenientDialogDisplayer.getDefault().displayError("Server address is incorrect.");
62+
}
63+
}
5264
if (ex instanceof AuthenticationFailedException) {
5365
authenticationException = (AuthenticationFailedException) ex;
5466
ConvenientDialogDisplayer.getDefault().displayError("Username or password is incorrect.", ex);
@@ -66,7 +78,10 @@ public void actionPerformed(ActionEvent e) {
6678
if (authenticationException != null) {
6779
throw authenticationException;
6880
}
69-
showOrganizations();
81+
if (connectionException != null) {
82+
throw connectionException;
83+
}
84+
showOrganizations();
7085
}
7186

7287
public void setReady(boolean value) {

0 commit comments

Comments
 (0)