From d6b4645cb90220334003c401bb0a495d0301f8d8 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 11 May 2018 17:48:57 -0600 Subject: [PATCH] Catch errors from the IRC bridge being down Fixes #184 --- src/bridges/IrcBridge.ts | 9 ++++++++- src/db/BridgeStore.ts | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/bridges/IrcBridge.ts b/src/bridges/IrcBridge.ts index 1b45d44..925a40c 100644 --- a/src/bridges/IrcBridge.ts +++ b/src/bridges/IrcBridge.ts @@ -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")); diff --git a/src/db/BridgeStore.ts b/src/db/BridgeStore.ts index 5c502b9..dac1c21 100644 --- a/src/db/BridgeStore.ts +++ b/src/db/BridgeStore.ts @@ -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;