summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-29 23:35:59 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-29 23:35:59 +1000
commit071b171b5f33f33c1b5f8b7bb6ea77fa568e1542 (patch)
treeeb91ca448baa24d46eea0c5c8dedb90f7c017e95
parent/-/monitorz endpoint for system perf mon (diff)
downloadserver-071b171b5f33f33c1b5f8b7bb6ea77fa568e1542.tar.xz
add try/catch to fetch in slowcord status monitor
-rw-r--r--slowcord/status/src/index.ts22
1 files 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<number> => new Promise((resolve, reject) => {
 	const opts = {
@@ -85,7 +85,7 @@ const makeTimedRequest = (path: string, body?: object): Promise<number> => 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));
 	};