@@ -112,6 +112,8 @@ function parseQs(location) {
112112// Here, we do some crude URL analysis to allow
113113// deep-linking.
114114function routeUrl ( location ) {
115+ if ( ! window . matrixChat ) return ;
116+
115117 console . log ( "Routing URL " + window . location ) ;
116118 var params = parseQs ( location ) ;
117119 var loginToken = params . loginToken ;
@@ -189,7 +191,8 @@ function getConfig() {
189191 { method : "GET" , url : "config.json" , json : true } ,
190192 ( err , response , body ) => {
191193 if ( err || response . status < 200 || response . status >= 300 ) {
192- throw "failed to load config.json" ;
194+ deferred . reject ( { err : err , response : response } ) ;
195+ return ;
193196 }
194197
195198 deferred . resolve ( body ) ;
@@ -213,10 +216,26 @@ async function loadApp() {
213216 }
214217 }
215218
216- let configJson = await getConfig ( ) ;
219+ let configJson ;
220+ let configError ;
221+ try {
222+ configJson = await getConfig ( ) ;
223+ } catch ( e ) {
224+ // On 404 errors, carry on without a config,
225+ // but on other errors, fail, otherwise it will
226+ // lead to subtle errors where the app runs with
227+ // the default config if it fails to fetch config.json.
228+ if ( e . response . status != 404 ) {
229+ configError = e ;
230+ }
231+ }
217232
218233 console . log ( "Vector starting at " + window . location ) ;
219- if ( validBrowser ) {
234+ if ( configError ) {
235+ window . matrixChat = ReactDOM . render ( < div className = "error" >
236+ Unable to load config file: please refresh the page to try again.
237+ </ div > , document . getElementById ( 'matrixchat' ) ) ;
238+ } else if ( validBrowser ) {
220239 var MatrixChat = sdk . getComponent ( 'structures.MatrixChat' ) ;
221240 var fragParts = parseQsFromFragment ( window . location ) ;
222241 window . matrixChat = ReactDOM . render (
0 commit comments