Don't crash if bridges are offline

Fixes https://github.com/turt2live/matrix-dimension/issues/131
This commit is contained in:
Travis Ralston 2019-04-13 17:06:43 -06:00
parent 8cd5067e73
commit 266cf8c0d8
5 changed files with 157 additions and 117 deletions

View file

@ -140,6 +140,7 @@ export class GitterBridge {
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("GitterBridge", "Error calling " + url);
LogService.error("GitterBridge", err);
@ -156,6 +157,10 @@ export class GitterBridge {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("GitterBridge", e);
reject(e);
}
});
});
}
@ -173,6 +178,7 @@ export class GitterBridge {
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("GitterBridge", "Error calling" + url);
LogService.error("GitterBridge", err);
@ -189,6 +195,10 @@ export class GitterBridge {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("GitterBridge", e);
reject(e);
}
});
});
}

View file

@ -281,6 +281,7 @@ export class IrcBridge {
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("IrcBridge", "Error calling " + url);
LogService.error("IrcBridge", err);
@ -296,6 +297,10 @@ export class IrcBridge {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("IrcBridge", e);
reject(e);
}
});
});
}
@ -313,6 +318,7 @@ export class IrcBridge {
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("IrcBridge", "Error calling" + url);
LogService.error("IrcBridge", err);
@ -328,6 +334,10 @@ export class IrcBridge {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("IrcBridge", e);
reject(e);
}
});
});
}

View file

@ -257,6 +257,7 @@ export class SlackBridge {
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("SlackBridge", "Error calling " + url);
LogService.error("SlackBridge", err);
@ -273,6 +274,10 @@ export class SlackBridge {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("SlackBridge", e);
reject(e);
}
});
});
}
@ -290,6 +295,7 @@ export class SlackBridge {
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("SlackBridge", "Error calling" + url);
LogService.error("SlackBridge", err);
@ -306,6 +312,10 @@ export class SlackBridge {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("SlackBridge", e);
reject(e);
}
});
});
}

View file

@ -209,6 +209,7 @@ export class TelegramBridge {
"Authorization": `Bearer ${bridge.sharedSecret}`,
},
}, (err, res, _body) => {
try {
if (err) {
LogService.error("TelegramBridge", "Error calling" + url);
LogService.error("TelegramBridge", err);
@ -225,6 +226,10 @@ export class TelegramBridge {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("TelegramBridge", e);
reject(e);
}
});
});
}

View file

@ -78,6 +78,7 @@ export class WebhooksBridge {
qs: qs,
json: body,
}, (err, res, _body) => {
try {
if (err) {
LogService.error("WebhooksBridge", "Error calling" + url);
LogService.error("WebhooksBridge", err);
@ -93,6 +94,10 @@ export class WebhooksBridge {
if (typeof (res.body) === "string") res.body = JSON.parse(res.body);
resolve(res.body);
}
} catch (e) {
LogService.error("WebhooksBridge", e);
reject(e);
}
});
});
}