Add safety check for monitor
This commit is contained in:
1 parent
d1add402b0
commit
8ac53a9e16
3 files changed
+14
-3
No files matched your search
@@ -280,6 +280,9 @@ const getMonitorStatsById = async (req) => {
|
||||
const getMonitorById = async (monitorId) => {
|
||||
try {
|
||||
const monitor = await Monitor.findById(monitorId);
|
||||
if (monitor === null || monitor === undefined) {
|
||||
throw new Error(errorMessages.DB_FIND_MONTIOR_BY_ID(monitorId));
|
||||
}
|
||||
// Get notifications
|
||||
const notifications = await Notification.find({
|
||||
monitorId: monitorId,
|
||||
|
||||
+3
-3
@@ -140,9 +140,9 @@ const startApp = async () => {
|
||||
}
|
||||
process.exit(0);
|
||||
};
|
||||
process.on("SIGUSR2", cleanup);
|
||||
process.on("SIGINT", cleanup);
|
||||
process.on("SIGTERM", cleanup);
|
||||
// process.on("SIGUSR2", cleanup);
|
||||
// process.on("SIGINT", cleanup);
|
||||
// process.on("SIGTERM", cleanup);
|
||||
};
|
||||
|
||||
startApp().catch((error) => {
|
||||
|
||||
@@ -16,6 +16,7 @@ class NetworkService {
|
||||
}
|
||||
|
||||
async handleNotification(job, isAlive) {
|
||||
try {
|
||||
const { _id } = job.data;
|
||||
const monitor = await this.db.getMonitorById(_id);
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user