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) }) }