Add error logging via ntfy

This commit is contained in:
Christopher Cookman 2024-05-12 01:44:22 -06:00
parent 1e94c43aea
commit 4072116aa5
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
2 changed files with 46 additions and 6 deletions

View file

@ -1,4 +1,5 @@
{ {
"debug": 0,
"priorityColors": { "priorityColors": {
"1": "#00AFFF", "1": "#00AFFF",
"2": "#00FF00", "2": "#00FF00",
@ -8,14 +9,21 @@
}, },
"discord": { "discord": {
"token": "YOUR_TOKEN", "token": "YOUR_TOKEN",
"owner": "your_user_id", "owner": "YOUR_ID",
"mainGuild": "your_guild_id", "mainGuild": "YOUR_GUILD",
"inviteChannel": "your_channel_id" "inviteChannel": "INVITE_CHANNEL",
"logChannel": "LOG_CHANNEL"
}, },
"ntfy": { "ntfy": {
"enabled": false, "enabled": false,
"server": "https://Example.com", "server": "https://your.ntfy.server",
"token": "ntfy_access_token", "token": "tk_XXXXXXXXXXXXXXXX",
"prefix": "iem-" "prefix": "iem-",
"errors": "iem-errors"
},
"broadcastify": {
"enabled": false,
"username": "YOUR_USERNAME",
"password": "YOUR_PASSWORD"
} }
} }

View file

@ -1133,10 +1133,42 @@ discord.on("guildDelete", (guild) => {
process.on("unhandledRejection", (error) => { process.on("unhandledRejection", (error) => {
console.log(`${colors.red("[ERROR]")} Unhandled Rejection: ${error.message}`); console.log(`${colors.red("[ERROR]")} Unhandled Rejection: ${error.message}`);
if (config.ntfy.enabled) {
fetch(config.ntfy.server, {
method: 'POST',
body: JSON.stringify({
"topic": config.ntfy.errors,
"message": `Unhandled Rejection: ${error.message}`,
"tags": ["Error"],
"priority": 5
}),
headers: {
'Authorization': `Bearer ${config.ntfy.token}`
}
}).catch((err) => {
console.error(err)
})
}
}); });
process.on("uncaughtException", (error) => { process.on("uncaughtException", (error) => {
console.log(`${colors.red("[ERROR]")} Uncaught Exception: ${error.message}\n${error.stack}`); console.log(`${colors.red("[ERROR]")} Uncaught Exception: ${error.message}\n${error.stack}`);
if (config.ntfy.enabled) {
fetch(config.ntfy.server, {
method: 'POST',
body: JSON.stringify({
"topic": config.ntfy.errors,
"message": `Uncaught Exception: ${error.message}\n${error.stack}`,
"tags": ["Error"],
"priority": 5
}),
headers: {
'Authorization': `Bearer ${config.ntfy.token}`
}
}).catch((err) => {
console.error(err)
})
}
}); });
// Login to discord // Login to discord