You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/03/27 19:45:13 UTC
[6/6] js commit: catch XHR exception in cordova_plugins.json loading
code
catch XHR exception in cordova_plugins.json loading code
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/a2c5b0e2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/a2c5b0e2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/a2c5b0e2
Branch: refs/heads/2.6.x
Commit: a2c5b0e22026926f04df300436e9fb4574377a62
Parents: dad383c
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Mar 27 11:44:05 2013 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Mar 27 11:44:05 2013 -0700
----------------------------------------------------------------------
lib/scripts/plugin_loader.js | 34 ++++++++++++++++++++--------------
1 files changed, 20 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/a2c5b0e2/lib/scripts/plugin_loader.js
----------------------------------------------------------------------
diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js
index 8e4161d..5223221 100644
--- a/lib/scripts/plugin_loader.js
+++ b/lib/scripts/plugin_loader.js
@@ -92,22 +92,28 @@
}
}
+
// Try to XHR the cordova_plugins.json file asynchronously.
- var xhr = new context.XMLHttpRequest();
- xhr.onload = function() {
- // 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.
- var obj = JSON.parse(this.responseText);
- if (obj && obj instanceof Array && obj.length > 0) {
- handlePluginsObject(obj);
- } else {
+ try { // we commented we were going to try, so let us actually try and catch
+ var xhr = new context.XMLHttpRequest();
+ xhr.onload = function() {
+ // 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.
+ var obj = JSON.parse(this.responseText);
+ if (obj && obj instanceof Array && obj.length > 0) {
+ handlePluginsObject(obj);
+ } else {
+ finishPluginLoading();
+ }
+ };
+ xhr.onerror = function() {
finishPluginLoading();
- }
- };
- xhr.onerror = function() {
+ };
+ xhr.open('GET', 'cordova_plugins.json', true); // Async
+ xhr.send();
+ }
+ catch(err){
finishPluginLoading();
- };
- xhr.open('GET', 'cordova_plugins.json', true); // Async
- xhr.send();
+ }
}(window));