catch XHR exception in cordova_plugins.json loading code
diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js
index ef4f446..63ff349 100644
--- a/lib/scripts/plugin_loader.js
+++ b/lib/scripts/plugin_loader.js
@@ -93,26 +93,31 @@
}
// Try to XHR the cordova_plugins.json file asynchronously.
- var xhr = new context.XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (this.readyState != 4) { // not DONE
- return;
- }
+ try { // we commented we were going to try, so let us actually try and catch
+ var xhr = new context.XMLHttpRequest();
+ xhr.onreadystatechange = function() {
+ if (this.readyState != 4) { // not DONE
+ return;
+ }
- // If the response is a JSON string which composes an array, call handlePluginsObject.
- // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
- if (this.status == 200) {
- var obj = JSON.parse(this.responseText);
- if (obj && obj instanceof Array && obj.length > 0) {
- handlePluginsObject(obj);
+ // If the response is a JSON string which composes an array, call handlePluginsObject.
+ // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
+ if (this.status == 200) {
+ var obj = JSON.parse(this.responseText);
+ if (obj && obj instanceof Array && obj.length > 0) {
+ handlePluginsObject(obj);
+ } else {
+ finishPluginLoading();
+ }
} else {
finishPluginLoading();
}
- } else {
- finishPluginLoading();
- }
- };
- xhr.open('GET', 'cordova_plugins.json', true); // Async
- xhr.send();
+ };
+ xhr.open('GET', 'cordova_plugins.json', true); // Async
+ xhr.send();
+ }
+ catch(err) {
+ finishPluginLoading();
+ }
}(window));