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:58:16 UTC
js commit: catch XHR exception in cordova_plugins.json loading code
Updated Branches:
refs/heads/2.6.x a2c5b0e22 -> 104709b21 (forced update)
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/104709b2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/104709b2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/104709b2
Branch: refs/heads/2.6.x
Commit: 104709b2130a29e7ad8596d1a6cee1ed48138803
Parents: 47593b2
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Mar 27 11:56:02 2013 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Mar 27 11:56:02 2013 -0700
----------------------------------------------------------------------
lib/scripts/plugin_loader.js | 39 ++++++++++++++++++++----------------
1 files changed, 22 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/104709b2/lib/scripts/plugin_loader.js
----------------------------------------------------------------------
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));