add error handling util, update middleware and controllers

This commit is contained in:
Alex Holliday committed 2025-07-15 16:33:35 -07:00
1 parent c54feb9306
commit 38bb915144
15 files changed
+683 -852

No files matched your search

+3 -15
View File
@@ -1,16 +1,4 @@
const handleValidationError = (error, serviceName) => {
error.status = 422;
error.service = serviceName;
error.message = error.details?.[0]?.message || error.message || "Validation Error";
return error;
};
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;
};
import { createServerError } from "../utils/errorUtils.js";
const fetchMonitorCertificate = async (sslChecker, monitor) => {
const monitorUrl = new URL(monitor.url);
@@ -18,9 +6,9 @@ const fetchMonitorCertificate = async (sslChecker, monitor) => {
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");
throw createServerError("Certificate not found");
}
return cert;
};
export { handleValidationError, handleError, fetchMonitorCertificate };
export { fetchMonitorCertificate };