diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/statusbot/statusbot.js | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/modules/statusbot/statusbot.js b/modules/statusbot/statusbot.js index a518b17..eb554e6 100644 --- a/modules/statusbot/statusbot.js +++ b/modules/statusbot/statusbot.js @@ -158,11 +158,19 @@ function augmentConfig(config, cb) { // wait a bit with requesting this in case the homeserver in question is the same server as us pretry(500, 1.2, 10, cb => { + console.log("statusbot: Attempting to get matrix server info"); fetch("GET", {}, home_server, "/.well-known/matrix/server", "", (status, body) => { if (status != 200) { cb(false); // attempt failed (perhaps a later attempt will succeed) + return; + } + let mserver; + try { + mserver = JSON.parse(body)["m.server"]; + } catch (e) { + cb(false); // invalid JSON response, try again later + return; } - const mserver = JSON.parse(body)["m.server"]; const m = mserver.match(/^([^:]*)(:443)?$/); if (!m) { throw new Error(`statusbot: Matrix server port not 443 (sorry): <${mserver}>`); @@ -173,8 +181,10 @@ function augmentConfig(config, cb) { }); }, (success, state) => { - if (success) cb(state); - else throw new Error(`statusbot: Failed getting https://${home_server}/.well-known/matrix/server`); + if (success) { + console.log("statusbot: Successfully got matrix server info."); + cb(state); + } else throw new Error(`statusbot: Failed getting https://${home_server}/.well-known/matrix/server`); } ); } |