1
0
mirror of https://github.com/etesync/android synced 2024-11-15 12:28:57 +00:00

Handle failing to connect to server during login.

This commit is contained in:
Tom Hacohen 2017-02-16 11:59:34 +00:00
parent eb9c3aa907
commit c33bc0ee19
2 changed files with 10 additions and 15 deletions

View File

@ -31,7 +31,7 @@ public class JournalAuthenticator {
}
}
public String getAuthToken(String username, String password) throws Exceptions.HttpException {
public String getAuthToken(String username, String password) throws Exceptions.HttpException, IOException {
FormBody.Builder formBuilder = new FormBody.Builder()
.add("username", username)
.add("password", password);
@ -41,19 +41,13 @@ public class JournalAuthenticator {
.url(remote)
.build();
try {
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
return GsonHelper.gson.fromJson(response.body().charStream(), AuthResponse.class).token;
} else if (response.code() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new Exceptions.UnauthorizedException("Username or password incorrect");
} else {
throw new Exceptions.HttpException(response);
}
} catch (IOException e) {
App.log.log(Level.SEVERE, "Couldn't download external resource", e);
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
return GsonHelper.gson.fromJson(response.body().charStream(), AuthResponse.class).token;
} else if (response.code() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new Exceptions.UnauthorizedException("Username or password incorrect");
} else {
throw new Exceptions.HttpException(response);
}
return null;
}
}

View File

@ -10,6 +10,7 @@ package at.bitfire.davdroid.ui.setup;
import android.content.Context;
import android.support.annotation.NonNull;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
import java.util.HashMap;
@ -59,7 +60,7 @@ public class BaseConfigurationFinder {
String authtoken = null;
try {
authtoken = authenticator.getAuthToken(credentials.userName, credentials.password);
} catch (Exceptions.HttpException e) {
} catch (Exceptions.HttpException|IOException e) {
log.warning(e.getMessage());
failed = true;