Files
Checkmate/Server/controllers/controllerUtils.js
2024-10-17 11:57:37 +08:00

27 lines
817 B
JavaScript

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;
};
const fetchMonitorCertificate = async (sslChecker, monitor) => {
try {
const monitorUrl = new URL(monitor.url);
const hostname = monitorUrl.hostname;
const cert = await sslChecker(hostname);
return cert;
} catch (error) {
throw error;
}
};
export { handleValidationError, handleError, fetchMonitorCertificate };