From f6aa9a7ea48efda6a597ead25b1d0774de847dda Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 8 Jun 2016 18:46:21 +0100 Subject: [PATCH] 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 771037863..bd12bdf9c 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 9ecf8f813..c2e16108e 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 28e148537..000000000 --- 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