fix: enhance error handling in daily digest notifications
This commit is contained in:
30
index.ts
30
index.ts
@@ -39,9 +39,10 @@ ${usage}
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
Title: `Daily Digest for ${dayjs().format("YYYY-MM-DD")}`,
|
||||
Title: `Daily Digest for ${dayjs().format("YYYY-MM-DD")}: Error`,
|
||||
Markdown: "yes",
|
||||
Tags: "calendar"
|
||||
Tags: "calendar",
|
||||
Priority: "max"
|
||||
},
|
||||
body: message,
|
||||
},
|
||||
@@ -54,8 +55,29 @@ ${usage}
|
||||
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 * * *", () => {
|
||||
main().catch((err) => {
|
||||
runMain().catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
})
|
||||
@@ -76,7 +98,7 @@ es.onmessage = (e) => {
|
||||
const msg = JSON.parse(e.data).message as string
|
||||
|
||||
if (msg === "/digest") {
|
||||
main().catch((err) => {
|
||||
runMain().catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user