Catch errors from the IRC bridge being down

Fixes #184
This commit is contained in:
Travis Ralston 2018-05-11 17:48:57 -06:00
parent 8f98716217
commit d6b4645cb9
2 changed files with 20 additions and 7 deletions

View File

@ -282,9 +282,12 @@ export class IrcBridge {
json: body,
}, (err, res, _body) => {
if (err) {
LogService.error("IrcBridge", "Error calling" + url);
LogService.error("IrcBridge", "Error calling " + url);
LogService.error("IrcBridge", err);
reject(err);
} else if (!res) {
LogService.error("IrcBridge", "There is no response for " + url);
reject(new Error("No response provided - is the service online?"));
} else if (res.statusCode !== 200) {
LogService.error("IrcBridge", "Got status code " + res.statusCode + " when calling " + url);
LogService.error("IrcBridge", res.body);
@ -314,6 +317,10 @@ export class IrcBridge {
LogService.error("IrcBridge", "Error calling" + url);
LogService.error("IrcBridge", err);
reject(err);
} else if (!res) {
LogService.error("IrcBridge", "There is no response for " + url);
reject(new Error("No response provided - is the service online?"));
} else if (res.statusCode !== 200) {
LogService.error("IrcBridge", "Got status code " + res.statusCode + " when calling " + url);
LogService.error("IrcBridge", res.body);
reject(new Error("Request failed"));

View File

@ -1,6 +1,7 @@
import { Bridge } from "../integrations/Bridge";
import BridgeRecord from "./models/BridgeRecord";
import { IrcBridge } from "../bridges/IrcBridge";
import { LogService } from "matrix-js-snippets";
export class BridgeStore {
@ -12,13 +13,18 @@ export class BridgeStore {
const enabledBridges: Bridge[] = [];
for (const bridgeRecord of allRecords) {
if (isEnabled === true || isEnabled === false) {
const isLogicallyEnabled = await BridgeStore.isLogicallyEnabled(bridgeRecord, requestingUserId);
if (isLogicallyEnabled !== isEnabled) continue;
}
try {
if (isEnabled === true || isEnabled === false) {
const isLogicallyEnabled = await BridgeStore.isLogicallyEnabled(bridgeRecord, requestingUserId);
if (isLogicallyEnabled !== isEnabled) continue;
}
const bridgeConfig = await BridgeStore.getConfiguration(bridgeRecord, requestingUserId, inRoomId);
enabledBridges.push(new Bridge(bridgeRecord, bridgeConfig));
const bridgeConfig = await BridgeStore.getConfiguration(bridgeRecord, requestingUserId, inRoomId);
enabledBridges.push(new Bridge(bridgeRecord, bridgeConfig));
} catch (e) {
LogService.error("BridgeStore", "Failed to load configuration for bridge: " + bridgeRecord.name);
LogService.error("BridgeStore", e);
}
}
return enabledBridges;