From fb0ead89b7a92321e534ec5992ed297ec92409db Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 24 Oct 2024 11:35:58 +0800 Subject: [PATCH] Refactor fetchMonitorCertificate to throw an error if invald cert --- Server/controllers/controllerUtils.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Server/controllers/controllerUtils.js b/Server/controllers/controllerUtils.js index 38c45b3cb..bee091db8 100644 --- a/Server/controllers/controllerUtils.js +++ b/Server/controllers/controllerUtils.js @@ -17,6 +17,10 @@ const fetchMonitorCertificate = async (sslChecker, monitor) => { const monitorUrl = new URL(monitor.url); const hostname = monitorUrl.hostname; const cert = await sslChecker(hostname); + // Throw an error if no cert or if cert.validTo is not present + if (cert?.validTo === null || cert?.validTo === undefined) { + throw new Error("Certificate not found"); + } return cert; } catch (error) { throw error;