From f6aa9a7ea48efda6a597ead25b1d0774de847dda Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 8 Jun 2016 18:46:21 +0100 Subject: [PATCH 1/7] Make the config optional Accept 404 errors from getting the config and start MatrixChat with no config, make other errors display a simple error message to prevent a completely blank page if the config does fail to load. --- .../views/settings/Notifications.js | 2 ++ src/vector/index.js | 24 ++++++++++++++++--- vector/config.json | 1 - config.json => vector/config.sample.json | 0 4 files changed, 23 insertions(+), 4 deletions(-) delete mode 120000 vector/config.json rename config.json => vector/config.sample.json (100%) diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js index 77103786..bd12bdf9 100644 --- a/src/components/views/settings/Notifications.js +++ b/src/components/views/settings/Notifications.js @@ -121,6 +121,8 @@ module.exports = React.createClass({ var data = {} if (this.props.brand) { data['brand'] = this.props.brand; + } else if (this.props.brand === undefined) { + data['brand'] = 'Vector'; } emailPusherPromise = UserSettingsStore.addEmailPusher(address, data); } else { diff --git a/src/vector/index.js b/src/vector/index.js index 9ecf8f81..c2e16108 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -79,6 +79,7 @@ var validBrowser = checkBrowserFeatures([ "displaytable", "flexbox", "es5object", "es5function", "localstorage", "objectfit" ]); +var configError; // We want to support some name / value pairs in the fragment // so we're re-using query string like format @@ -112,6 +113,8 @@ function parseQs(location) { // Here, we do some crude URL analysis to allow // deep-linking. function routeUrl(location) { + if (!window.matrixChat) return; + console.log("Routing URL "+window.location); var params = parseQs(location); var loginToken = params.loginToken; @@ -189,7 +192,7 @@ function getConfig() { { method: "GET", url: "config.json", json: true }, (err, response, body) => { if (err || response.status < 200 || response.status >= 300) { - throw "failed to load config.json"; + deferred.reject({err: err, response: response}); } deferred.resolve(body); @@ -213,10 +216,25 @@ async function loadApp() { } } - let configJson = await getConfig(); + let configJson; + try { + configJson = await getConfig(); + } catch (e) { + // On 404 errors, carry on without a config, + // but on other errors, fail, otherwise it will + // lead to subtle errors where the app runs with + // the default config it fails to fetch config.json. + if (e.response.status != 404) { + configError = e; + } + } console.log("Vector starting at "+window.location); - if (validBrowser) { + if (configError) { + window.matrixChat = ReactDOM.render(
+ Unable to load config file: please refresh the page to try again. +
, document.getElementById('matrixchat')); + } else if (validBrowser) { var MatrixChat = sdk.getComponent('structures.MatrixChat'); var fragParts = parseQsFromFragment(window.location); window.matrixChat = ReactDOM.render( diff --git a/vector/config.json b/vector/config.json deleted file mode 120000 index 28e14853..00000000 --- a/vector/config.json +++ /dev/null @@ -1 +0,0 @@ -../config.json \ No newline at end of file diff --git a/config.json b/vector/config.sample.json similarity index 100% rename from config.json rename to vector/config.sample.json From 4fc311da90ab976e9df88b680b6f92b631f6e3b6 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Jun 2016 09:56:11 +0100 Subject: [PATCH 2/7] Style fix --- src/components/views/settings/Notifications.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js index bd12bdf9..a6908118 100644 --- a/src/components/views/settings/Notifications.js +++ b/src/components/views/settings/Notifications.js @@ -120,9 +120,7 @@ module.exports = React.createClass({ if (event.target.checked) { var data = {} if (this.props.brand) { - data['brand'] = this.props.brand; - } else if (this.props.brand === undefined) { - data['brand'] = 'Vector'; + data['brand'] = this.props.brand || 'Vector'; } emailPusherPromise = UserSettingsStore.addEmailPusher(address, data); } else { From e4ea00ca23f6d4e28340338787697cc6fe193621 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Jun 2016 09:56:57 +0100 Subject: [PATCH 3/7] Return here, else we'll call resolve too --- src/vector/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vector/index.js b/src/vector/index.js index c2e16108..e5850f41 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -193,6 +193,7 @@ function getConfig() { (err, response, body) => { if (err || response.status < 200 || response.status >= 300) { deferred.reject({err: err, response: response}); + return; } deferred.resolve(body); From 3040d0a474832a629db5b4a329a9520187155328 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Jun 2016 09:57:44 +0100 Subject: [PATCH 4/7] Comment typo --- src/vector/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/index.js b/src/vector/index.js index e5850f41..4b4e3a95 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -224,7 +224,7 @@ async function loadApp() { // On 404 errors, carry on without a config, // but on other errors, fail, otherwise it will // lead to subtle errors where the app runs with - // the default config it fails to fetch config.json. + // the default config if fails to fetch config.json. if (e.response.status != 404) { configError = e; } From 24602119c5f20bb9df8b23294f78c08ca258c3a3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Jun 2016 09:59:37 +0100 Subject: [PATCH 5/7] This doesn't actually need to be global (because the rendering isn't in a render method here) --- src/vector/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/index.js b/src/vector/index.js index 4b4e3a95..9f98cf97 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -79,7 +79,6 @@ var validBrowser = checkBrowserFeatures([ "displaytable", "flexbox", "es5object", "es5function", "localstorage", "objectfit" ]); -var configError; // We want to support some name / value pairs in the fragment // so we're re-using query string like format @@ -218,6 +217,7 @@ async function loadApp() { } let configJson; + let configError; try { configJson = await getConfig(); } catch (e) { From f595f6f141f2c417f494be55393d1cf3916429bb Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 9 Jun 2016 10:25:49 +0100 Subject: [PATCH 6/7] This check shouldn't be here with the || --- src/components/views/settings/Notifications.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js index a6908118..7f0b5754 100644 --- a/src/components/views/settings/Notifications.js +++ b/src/components/views/settings/Notifications.js @@ -119,9 +119,7 @@ module.exports = React.createClass({ var emailPusherPromise; if (event.target.checked) { var data = {} - if (this.props.brand) { - data['brand'] = this.props.brand || 'Vector'; - } + data['brand'] = this.props.brand || 'Vector'; emailPusherPromise = UserSettingsStore.addEmailPusher(address, data); } else { var emailPusher = UserSettingsStore.getEmailPusher(this.state.pushers, address); From 4dd477e064023895633e52597457f03d8989ce9c Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 9 Jun 2016 10:38:51 +0100 Subject: [PATCH 7/7] index.js: fix comment typo Fix dave's typo for him --- src/vector/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/index.js b/src/vector/index.js index 9f98cf97..08d89c3d 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -224,7 +224,7 @@ async function loadApp() { // On 404 errors, carry on without a config, // but on other errors, fail, otherwise it will // lead to subtle errors where the app runs with - // the default config if fails to fetch config.json. + // the default config if it fails to fetch config.json. if (e.response.status != 404) { configError = e; }