From 071b171b5f33f33c1b5f8b7bb6ea77fa568e1542 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 29 Aug 2022 23:35:59 +1000 Subject: add try/catch to fetch in slowcord status monitor --- slowcord/status/src/index.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/slowcord/status/src/index.ts b/slowcord/status/src/index.ts index 82a15d1c..afec4743 100644 --- a/slowcord/status/src/index.ts +++ b/slowcord/status/src/index.ts @@ -58,7 +58,7 @@ const saveSystemUsage = async (load: number, procUptime: number, sysUptime: numb catch (e) { console.error(e); } -} +}; const makeTimedRequest = (path: string, body?: object): Promise => new Promise((resolve, reject) => { const opts = { @@ -85,7 +85,7 @@ const makeTimedRequest = (path: string, body?: object): Promise => new P res.on("end", () => { end = Date.now(); resolve(end - start); - }) + }); }); req.on("finish", () => { @@ -134,13 +134,17 @@ const app = async () => { await measureApi("login", `${instance.app}/login`); // await gatewayMeasure("websocketPing"); - const res = await fetch(`${instance.api}/-/monitorz`, { - headers: { - Authorization: process.env.INSTANCE_TOKEN as string, - } - }); - const json = await res.json() as monitorzSchema; - await saveSystemUsage(json.load[2], json.procUptime, json.sysUptime, json.memPercent); + try { + const res = await fetch(`${instance.api}/-/monitorz`, { + headers: { + Authorization: process.env.INSTANCE_TOKEN as string, + } + }); + const json = await res.json() as monitorzSchema; + await saveSystemUsage(json.load[1], json.procUptime, json.sysUptime, json.memPercent); + } + catch (e) { + } setTimeout(doMeasurements, parseInt(process.env.MEASURE_INTERVAL as string)); }; -- cgit 1.4.1