Skip to content

Commit

Permalink
Merge pull request louislam#2393 from zImPatrick/discord-docker-fix
Browse files Browse the repository at this point in the history
Fix discord notification not sending when docker container goes down
  • Loading branch information
louislam authored Dec 24, 2022
2 parents 6962e05 + 14fffcf commit 1e689d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,13 @@ class Monitor extends BeanModel {

for (let notification of notificationList) {
try {
await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), bean.toJSON());
// Prevent if the msg is undefined, notifications such as Discord cannot send out.
const heartbeatJSON = bean.toJSON();
if (!heartbeatJSON["msg"]) {
heartbeatJSON["msg"] = "";
}

await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), heartbeatJSON);
} catch (e) {
log.error("monitor", "Cannot send notification to " + notification.name);
log.error("monitor", e);
Expand Down
2 changes: 1 addition & 1 deletion server/notification-providers/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Discord extends NotificationProvider {
},
{
name: "Error",
value: heartbeatJSON["msg"],
value: heartbeatJSON["msg"] == null ? "N/A" : heartbeatJSON["msg"],
},
],
}],
Expand Down

0 comments on commit 1e689d9

Please sign in to comment.