Commit c3d8b001 authored by djamel's avatar djamel

catch and print: server error connection and empty port address

parent 78bdbe01
......@@ -50,7 +50,13 @@ public class Login extends ActionBarActivity implements View.OnClickListener {
final String server = "http://" + myIpString + ":" + myPortString;
// check if ip address is right
if (InetAddressUtils.isIPv4Address(myIpString)) {
if (!InetAddressUtils.isIPv4Address(myIpString)) {
display(getString(R.string.errorIP), false);
}
else if (myPortString.isEmpty()) {
display(getString(R.string.errorPORT), false);
}
else {
AsyncHttpClient client = new AsyncHttpClient();
client.get(server + "/keys", new JsonHttpResponseHandler() {
......@@ -78,11 +84,19 @@ public class Login extends ActionBarActivity implements View.OnClickListener {
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
display(getString(R.string.serverError), false);
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
display(getString(R.string.serverError), false);
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
display(getString(R.string.serverError), false);
}
});
}
else {
display(getString(R.string.errorIP), false);
}
}
......
......@@ -20,7 +20,8 @@
<string name="noQRCodeApplication">Auncun lecteur de QRCode n\'a été trouvé</string>
<string name="downloadQRCode">Télécharger un scanner ?</string>
<string name="serverError">Erreur: Communication serveur</string>
<string name="errorIP">Wrong IP Address: Please try with an IP Address in the following form:
\'192.168.0.1\'</string>
<string name="errorIP">Wrong IP Address: Please try with an IP Address in the following
form: \'192.168.0.1\'</string>
<string name="errorPORT">Wrong port number</string>
<string name="ex_3">ex: 3</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment