@@ -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.
114115function 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 (
0 commit comments