Add service name and method name to errors in notification and pageSpeedCheck modules

This commit is contained in:
Alex Holliday
2024-09-15 09:16:55 +08:00
parent f5fb32885e
commit b4fd895ea2
2 changed files with 12 additions and 0 deletions
@@ -15,6 +15,8 @@ const createNotification = async (notificationData) => {
const notification = await new Notification({ ...notificationData }).save();
return notification;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "createNotification";
throw error;
}
};
@@ -30,6 +32,8 @@ const getNotificationsByMonitorId = async (monitorId) => {
const notifications = await Notification.find({ monitorId });
return notifications;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getNotificationsByMonitorId";
throw error;
}
};
@@ -39,6 +43,8 @@ const deleteNotificationsByMonitorId = async (monitorId) => {
const result = await Notification.deleteMany({ monitorId });
return result.deletedCount;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "deleteNotificationsByMonitorId";
throw error;
}
};
@@ -19,6 +19,8 @@ const createPageSpeedCheck = async (pageSpeedCheckData) => {
}).save();
return pageSpeedCheck;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "createPageSpeedCheck";
throw error;
}
};
@@ -36,6 +38,8 @@ const getPageSpeedChecks = async (monitorId) => {
const pageSpeedChecks = await PageSpeedCheck.find({ monitorId });
return pageSpeedChecks;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getPageSpeedChecks";
throw error;
}
};
@@ -53,6 +57,8 @@ const deletePageSpeedChecksByMonitorId = async (monitorId) => {
const result = await PageSpeedCheck.deleteMany({ monitorId });
return result.deletedCount;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "deletePageSpeedChecksByMonitorId";
throw error;
}
};