From 82e1d8fb0c078163dc1e7534689e66cff9955324 Mon Sep 17 00:00:00 2001 From: Suraj B M Date: Fri, 24 Jul 2026 11:37:39 +0530 Subject: [PATCH] fix: enhance error handling in daily digest notifications --- index.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index ee7b4a9..68cc55e 100644 --- a/index.ts +++ b/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) }) }