fix(api): harden reminder and webhook delivery

This commit is contained in:
2026-03-31 22:36:53 +02:00
parent 0b192efdb1
commit 6d4de85660
4 changed files with 396 additions and 53 deletions
+10 -5
View File
@@ -7,6 +7,7 @@
* Fire-and-forget — errors are logged, never thrown.
*/
import { createHmac } from "node:crypto";
import { logger } from "./logger.js";
import { sendSlackNotification } from "./slack-notify.js";
/** Available webhook event types. */
@@ -72,7 +73,7 @@ async function _dispatch(
await Promise.allSettled(promises);
} catch (err) {
console.error("[webhook-dispatcher] failed to dispatch:", err);
logger.error({ err, event }, "Failed to dispatch webhooks");
}
}
@@ -108,19 +109,23 @@ async function _sendToWebhook(
const timeout = setTimeout(() => controller.abort(), 5_000);
try {
await fetch(wh.url, {
const response = await fetch(wh.url, {
method: "POST",
headers,
body,
signal: controller.signal,
});
if (!response.ok) {
throw new Error(`Webhook responded with HTTP ${response.status}`);
}
} finally {
clearTimeout(timeout);
}
} catch (err) {
console.error(
`[webhook-dispatcher] error sending to "${wh.name}" (${wh.id}):`,
err,
logger.warn(
{ err, event, webhookId: wh.id, webhookName: wh.name, webhookUrl: wh.url },
"Webhook delivery failed",
);
}
}