use of com.ichi2.anki.exception.UnknownHttpResponseException in project Anki-Android by ankidroid.
the class Connection method doInBackgroundLogin.
private Payload doInBackgroundLogin(Payload data) {
String username = (String) data.data[0];
String password = (String) data.data[1];
HostNum hostNum = (HostNum) data.data[2];
RemoteServer server = new RemoteServer(this, null, hostNum);
Response ret;
try {
ret = server.hostKey(username, password);
} catch (UnknownHttpResponseException e) {
Timber.w(e);
data.success = false;
data.resultType = ERROR;
data.result = new Object[] { e.getResponseCode(), e.getMessage() };
return data;
} catch (CustomSyncServerUrlException e2) {
Timber.w(e2);
data.success = false;
data.resultType = CUSTOM_SYNC_SERVER_URL;
data.result = new Object[] { e2 };
return data;
} catch (Exception e2) {
Timber.w(e2);
// Ask user to report all bugs which aren't timeout errors
if (!timeoutOccurred(e2)) {
AnkiDroidApp.sendExceptionReport(e2, "doInBackgroundLogin");
}
data.success = false;
data.resultType = CONNECTION_ERROR;
data.result = new Object[] { e2 };
return data;
}
String hostkey = null;
boolean valid = false;
if (ret != null) {
data.returnType = ret.code();
Timber.d("doInBackgroundLogin - response from server: %d, (%s)", data.returnType, ret.message());
if (data.returnType == 200) {
try {
JSONObject response = new JSONObject(ret.body().string());
hostkey = response.getString("key");
valid = (hostkey != null) && (hostkey.length() > 0);
} catch (JSONException e) {
Timber.w(e);
valid = false;
} catch (IllegalStateException | IOException | NullPointerException e) {
throw new RuntimeException(e);
}
}
} else {
Timber.e("doInBackgroundLogin - empty response from server");
}
if (valid) {
data.success = true;
data.data = new String[] { username, hostkey };
} else {
data.success = false;
}
return data;
}
Aggregations