Skip to content

Commit ab8b150

Browse files
committed
Better error messages when malformed server addresses
1 parent 2f9e70c commit ab8b150

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
import fi.helsinki.cs.tmc.coreimpl.TmcCoreSettingsImpl;
1616
import fi.helsinki.cs.tmc.events.LoginStateChangedEvent;
1717
import fi.helsinki.cs.tmc.model.CourseDb;
18+
import fi.helsinki.cs.tmc.tailoring.SelectedTailoring;
1819
import fi.helsinki.cs.tmc.ui.ConvenientDialogDisplayer;
1920
import fi.helsinki.cs.tmc.ui.CourseListWindow;
2021
import fi.helsinki.cs.tmc.ui.LoginDialog;
2122
import fi.helsinki.cs.tmc.ui.OrganizationListWindow;
2223

23-
import java.awt.event.ActionEvent;
24-
import java.awt.event.ActionListener;
2524
import java.io.FileNotFoundException;
2625
import java.io.IOException;
26+
import java.net.MalformedURLException;
2727
import java.net.UnknownHostException;
2828
import java.util.logging.Level;
2929
import java.util.logging.Logger;
@@ -69,26 +69,40 @@ public void run() {
6969
normalizer.selectOrganizationAndCourse();
7070
} catch (Exception ex) {
7171
log.log(Level.WARNING, "Error while logging in! " + ex.toString());
72+
final ConvenientDialogDisplayer displayer = ConvenientDialogDisplayer.getDefault();
73+
final TmcSettings settings = TmcSettingsHolder.get();
74+
final String serverAddress = settings.getServerAddress();
7275
if (ex instanceof IOException) {
7376
connectionException = (IOException) ex;
7477
if (ex instanceof UnknownHostException) {
75-
ConvenientDialogDisplayer.getDefault().displayError("Couldn't connect to the server. Please check your internet connection.");
78+
displayer.displayError("Couldn't connect to the server. Please check your internet connection.");
7679
} else if (ex instanceof FileNotFoundException) {
77-
if (TmcSettingsHolder.get().getServerAddress().contains("tmc.mooc.fi/mooc")) {
78-
ConvenientDialogDisplayer.getDefault().displayError("The server https://tmc.mooc.fi/mooc is no longer supported by this client.\n" +
80+
if (serverAddress.contains("tmc.mooc.fi/mooc")) {
81+
displayer.displayError("The server https://tmc.mooc.fi/mooc is no longer supported by this client.\n" +
7982
"All the courses have been migrated to our main server https://tmc.mooc.fi.\n" +
8083
"If you'd like to do the migrated courses, you'll need to update your server address to\n" +
81-
"https://tmc.mooc.fi/org/mooc and create a new account there.\n\n" +
84+
"https://tmc.mooc.fi and create a new account there.\n" +
85+
"After that, choose the MOOC organization after logging in.\n\n" +
8286
"For more information, check the course materials on mooc.fi.");
8387
} else {
84-
ConvenientDialogDisplayer.getDefault().displayError("Server address is incorrect or the server is not supported.");
88+
displayer.displayError("Server address is incorrect or the server is not supported.");
8589
}
90+
} else if (ex instanceof MalformedURLException) {
91+
displayer.displayError("Malformed server address! Resetting to default.");
92+
final String defaultServerUrl = SelectedTailoring.get().getDefaultServerUrl();
93+
settings.setServerAddress(defaultServerUrl);
8694
}
8795
} else if (ex instanceof AuthenticationFailedException) {
8896
authenticationException = (AuthenticationFailedException) ex;
89-
ConvenientDialogDisplayer.getDefault().displayError("Username or password is incorrect.", ex);
97+
displayer.displayError("Username or password is incorrect.", ex);
9098
} else {
91-
ConvenientDialogDisplayer.getDefault().displayError("Logging in failed! Try again.");
99+
if (serverAddress.contains("tmc.mooc.fi") && !serverAddress.contains("https://")) {
100+
displayer.displayError("Malformed server address! Resetting to default.");
101+
final String defaultServerUrl = SelectedTailoring.get().getDefaultServerUrl();
102+
settings.setServerAddress(defaultServerUrl);
103+
} else {
104+
displayer.displayError("Logging in failed! Try again.");
105+
}
92106
}
93107
}
94108
setReady(true);

0 commit comments

Comments
 (0)