Add error handling to notifications
This commit is contained in:
1 parent
071a7fc9cf
commit
4d61ecfe35
1 file changed
+24
-16
@@ -16,22 +16,30 @@ class NetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleNotification(monitor, isAlive) {
|
async handleNotification(monitor, isAlive) {
|
||||||
let template =
|
try {
|
||||||
isAlive === true ? "serverIsUpTemplate" : "serverIsDownTemplate";
|
let template =
|
||||||
let status = isAlive === true ? "up" : "down";
|
isAlive === true ? "serverIsUpTemplate" : "serverIsDownTemplate";
|
||||||
|
let status = isAlive === true ? "up" : "down";
|
||||||
|
|
||||||
const notifications = await this.db.getNotificationsByMonitorId(
|
const notifications = await this.db.getNotificationsByMonitorId(
|
||||||
monitor._id
|
monitor._id
|
||||||
);
|
);
|
||||||
for (const notification of notifications) {
|
for (const notification of notifications) {
|
||||||
if (notification.type === "email") {
|
if (notification.type === "email") {
|
||||||
await this.emailService.buildAndSendEmail(
|
await this.emailService.buildAndSendEmail(
|
||||||
template,
|
template,
|
||||||
{ monitorName: monitor.name, monitorUrl: monitor.url },
|
{ monitorName: monitor.name, monitorUrl: monitor.url },
|
||||||
notification.address,
|
notification.address,
|
||||||
`Monitor ${monitor.name} is ${status}`
|
`Monitor ${monitor.name} is ${status}`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error.message, {
|
||||||
|
method: "handleNotification",
|
||||||
|
service: this.SERVICE_NAME,
|
||||||
|
monitorId: monitor._id,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +50,7 @@ class NetworkService {
|
|||||||
|
|
||||||
if (monitor === null || monitor === undefined) {
|
if (monitor === null || monitor === undefined) {
|
||||||
logger.error(`Null Monitor: ${_id}`, {
|
logger.error(`Null Monitor: ${_id}`, {
|
||||||
method: "handleNotification",
|
method: "handleStatusUpdate",
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
jobId: job.id,
|
jobId: job.id,
|
||||||
});
|
});
|
||||||
@@ -69,7 +77,7 @@ class NetworkService {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error.message, {
|
logger.error(error.message, {
|
||||||
method: "handleNotification",
|
method: "handleStatusUpdate",
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
jobId: job.id,
|
jobId: job.id,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user