Skip to content

Commit f6aa9a7

Browse files
committed
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.
1 parent b3ae9cc commit f6aa9a7

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/components/views/settings/Notifications.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ module.exports = React.createClass({
121121
var data = {}
122122
if (this.props.brand) {
123123
data['brand'] = this.props.brand;
124+
} else if (this.props.brand === undefined) {
125+
data['brand'] = 'Vector';
124126
}
125127
emailPusherPromise = UserSettingsStore.addEmailPusher(address, data);
126128
} else {

src/vector/index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ var validBrowser = checkBrowserFeatures([
7979
"displaytable", "flexbox", "es5object", "es5function", "localstorage",
8080
"objectfit"
8181
]);
82+
var configError;
8283

8384
// We want to support some name / value pairs in the fragment
8485
// so we're re-using query string like format
@@ -112,6 +113,8 @@ function parseQs(location) {
112113
// Here, we do some crude URL analysis to allow
113114
// deep-linking.
114115
function routeUrl(location) {
116+
if (!window.matrixChat) return;
117+
115118
console.log("Routing URL "+window.location);
116119
var params = parseQs(location);
117120
var loginToken = params.loginToken;
@@ -189,7 +192,7 @@ function getConfig() {
189192
{ method: "GET", url: "config.json", json: true },
190193
(err, response, body) => {
191194
if (err || response.status < 200 || response.status >= 300) {
192-
throw "failed to load config.json";
195+
deferred.reject({err: err, response: response});
193196
}
194197

195198
deferred.resolve(body);
@@ -213,10 +216,25 @@ async function loadApp() {
213216
}
214217
}
215218

216-
let configJson = await getConfig();
219+
let configJson;
220+
try {
221+
configJson = await getConfig();
222+
} catch (e) {
223+
// On 404 errors, carry on without a config,
224+
// but on other errors, fail, otherwise it will
225+
// lead to subtle errors where the app runs with
226+
// the default config it fails to fetch config.json.
227+
if (e.response.status != 404) {
228+
configError = e;
229+
}
230+
}
217231

218232
console.log("Vector starting at "+window.location);
219-
if (validBrowser) {
233+
if (configError) {
234+
window.matrixChat = ReactDOM.render(<div className="error">
235+
Unable to load config file: please refresh the page to try again.
236+
</div>, document.getElementById('matrixchat'));
237+
} else if (validBrowser) {
220238
var MatrixChat = sdk.getComponent('structures.MatrixChat');
221239
var fragParts = parseQsFromFragment(window.location);
222240
window.matrixChat = ReactDOM.render(

vector/config.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)