mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-04-24 00:00:03 +08:00
Merge pull request #427 from moshe5745/master
Add "No connection" error response with status code -6
This commit is contained in:
@@ -16,6 +16,9 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
@@ -67,6 +70,15 @@ public class CordovaHttpPlugin extends CordovaPlugin implements Observer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!isNetworkAvailable()) {
|
||||||
|
CordovaHttpResponse response = new CordovaHttpResponse();
|
||||||
|
response.setStatus(-6);
|
||||||
|
response.setErrorMessage("Not Connected");
|
||||||
|
callbackContext.error(response.toJSON());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ("get".equals(action)) {
|
if ("get".equals(action)) {
|
||||||
return this.executeHttpRequestWithoutData(action, args, callbackContext);
|
return this.executeHttpRequestWithoutData(action, args, callbackContext);
|
||||||
} else if ("head".equals(action)) {
|
} else if ("head".equals(action)) {
|
||||||
@@ -249,4 +261,12 @@ public class CordovaHttpPlugin extends CordovaPlugin implements Observer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNetworkAvailable() {
|
||||||
|
ConnectivityManager connectivityManager
|
||||||
|
= (ConnectivityManager) cordova.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
||||||
|
|
||||||
|
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user