Merge pull request #772 from bluewave-labs/fix/unsafe-monitor-access

Add safety check for monitor
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-08-31 16:52:03 -07:00
commit 319e7c1f3d
2 files changed
+11

No files matched your search

+3
View File
@@ -280,6 +280,9 @@ const getMonitorStatsById = async (req) => {
const getMonitorById = async (monitorId) => { const getMonitorById = async (monitorId) => {
try { try {
const monitor = await Monitor.findById(monitorId); const monitor = await Monitor.findById(monitorId);
if (monitor === null || monitor === undefined) {
throw new Error(errorMessages.DB_FIND_MONTIOR_BY_ID(monitorId));
}
// Get notifications // Get notifications
const notifications = await Notification.find({ const notifications = await Notification.find({
monitorId: monitorId, monitorId: monitorId,
+8
View File
@@ -16,6 +16,7 @@ class NetworkService {
} }
async handleNotification(job, isAlive) { async handleNotification(job, isAlive) {
try {
const { _id } = job.data; const { _id } = job.data;
const monitor = await this.db.getMonitorById(_id); const monitor = await this.db.getMonitorById(_id);
if (monitor === null || monitor === undefined) { if (monitor === null || monitor === undefined) {
@@ -48,6 +49,13 @@ class NetworkService {
} }
} }
} }
} catch (error) {
logger.error(error.message, {
method: "handleNotification",
service: this.SERVICE_NAME,
jobId: job.id,
});
}
} }
/** /**