summaryrefslogtreecommitdiff
path: root/modules/statusbot
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-10-25 18:45:04 +0200
committerTom Smeding <tom@tomsmeding.com>2024-10-25 18:45:04 +0200
commit66b19013380f9dde2eb91b09a84dc7a271da3ac4 (patch)
tree84938c59be8a136915a5199770e6bac5dc8331b4 /modules/statusbot
parent109272df595b8d80c8301d92a734c0a369e11bae (diff)
statusbot: Fix well-known fetch loop
Diffstat (limited to 'modules/statusbot')
-rw-r--r--modules/statusbot/statusbot.js16
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`);
}
);
}