Refactor fetchMonitorCertificate to throw an error if invald cert

This commit is contained in:
Alex Holliday
2024-10-24 11:35:58 +08:00
parent 86eaae1754
commit fb0ead89b7
+4
View File
@@ -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;