1
0
mirror of https://github.com/etesync/android synced 2025-06-26 01:42:37 +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() FormBody.Builder formBuilder = new FormBody.Builder()
.add("username", username) .add("username", username)
.add("password", password); .add("password", password);
@ -41,19 +41,13 @@ public class JournalAuthenticator {
.url(remote) .url(remote)
.build(); .build();
try { Response response = client.newCall(request).execute();
Response response = client.newCall(request).execute(); if (response.isSuccessful()) {
if (response.isSuccessful()) { return GsonHelper.gson.fromJson(response.body().charStream(), AuthResponse.class).token;
return GsonHelper.gson.fromJson(response.body().charStream(), AuthResponse.class).token; } else if (response.code() == HttpURLConnection.HTTP_BAD_REQUEST) {
} else if (response.code() == HttpURLConnection.HTTP_BAD_REQUEST) { throw new Exceptions.UnauthorizedException("Username or password incorrect");
throw new Exceptions.UnauthorizedException("Username or password incorrect"); } else {
} else { throw new Exceptions.HttpException(response);
throw new Exceptions.HttpException(response);
}
} catch (IOException e) {
App.log.log(Level.SEVERE, "Couldn't download external resource", e);
} }
return null;
} }
} }

View File

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