fix: enhance error handling in daily digest notifications

This commit is contained in:
2026-07-24 11:37:39 +05:30
parent cc7ec85a5d
commit 82e1d8fb0c

View File

@@ -39,9 +39,10 @@ ${usage}
method: "POST", method: "POST",
headers: { headers: {
Authorization: `Bearer ${TOKEN}`, Authorization: `Bearer ${TOKEN}`,
Title: `Daily Digest for ${dayjs().format("YYYY-MM-DD")}`, Title: `Daily Digest for ${dayjs().format("YYYY-MM-DD")}: Error`,
Markdown: "yes", Markdown: "yes",
Tags: "calendar" Tags: "calendar",
Priority: "max"
}, },
body: message, body: message,
}, },
@@ -54,8 +55,29 @@ ${usage}
console.log("Notification sent at " + dayjs().format("YYYY-MM-dd HH:mm:ss")) console.log("Notification sent at " + dayjs().format("YYYY-MM-dd HH:mm:ss"))
} }
async function runMain() {
try {
await main()
} catch (err) {
console.error(err)
fetch(
`https://ntfy.hy-pr.link/${TOPIC}`,
{
method: "POST",
headers: {
Authorization: `Bearer ${TOKEN}`,
Title: `Daily Digest for ${dayjs().format("YYYY-MM-DD")}`,
Markdown: "yes",
Tags: "calendar"
},
body: `Error sending daily digest: ${(err as Error).message}`,
},
)
}
}
cron.schedule("0 7 * * *", () => { cron.schedule("0 7 * * *", () => {
main().catch((err) => { runMain().catch((err) => {
console.error(err) console.error(err)
}) })
}) })
@@ -76,7 +98,7 @@ es.onmessage = (e) => {
const msg = JSON.parse(e.data).message as string const msg = JSON.parse(e.data).message as string
if (msg === "/digest") { if (msg === "/digest") {
main().catch((err) => { runMain().catch((err) => {
console.error(err) console.error(err)
}) })
} }