Files
Checkmate/Server/controllers/controllerUtils.js
T

26 lines
942 B
JavaScript
Raw Normal View History

const handleValidationError = (error, serviceName) => {
error.status = 422;
error.service = serviceName;
error.message = error.details?.[0]?.message || error.message || "Validation Error";
return error;
};
2024-10-14 11:06:45 +08:00
const handleError = (error, serviceName, method, status = 500) => {
error.status === undefined ? (error.status = status) : null;
error.service === undefined ? (error.service = serviceName) : null;
error.method === undefined ? (error.method = method) : null;
return error;
};
const fetchMonitorCertificate = async (sslChecker, monitor) => {
2025-01-19 09:56:28 -08:00
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");
}
2025-01-19 09:56:28 -08:00
return cert;
};
2024-10-16 13:22:39 +08:00
export { handleValidationError, handleError, fetchMonitorCertificate };