Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Enhance webhook failure handling by adding consecutiveFailures tracking and updating notification emails. The webhook model now includes a consecutiveFailures property, and the email notification reflects the number of delivery failures, indicating the threshold for disabling the webhook.

Kiran K46f201eb5c48
diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.ts
index 3982aa66ec..7ad13bd915 100644
--- a/apps/web/app/api/webhooks/[webhookId]/route.ts
+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts
@@ -138,6 +138,7 @@ export const PATCH = withWorkspace(
},
}),
disabledAt: null,
+ consecutiveFailures: 0,
},
select: {
id: true,
diff --git a/apps/web/emails/webhook-failed.tsx b/apps/web/emails/webhook-failed.tsx
index 50327803de..d93e9fdae6 100644
--- a/apps/web/emails/webhook-failed.tsx
+++ b/apps/web/emails/webhook-failed.tsx
@@ -1,3 +1,4 @@
+import { WEBHOOK_FAILURE_DISABLE_THRESHOLD } from "@/lib/webhook/constants";
import { DUB_WORDMARK } from "@dub/utils";
import {
Body,
@@ -23,6 +24,7 @@ export default function WebhookFailed({
webhook = {
id: "wh_tYedrqsWgNJxUwQOaAnupcUJ1",
url: "https://example.com/webhook",
+ consecutiveFailures: 15,
},
}: {
email: string;
@@ -33,6 +35,7 @@ export default function WebhookFailed({
webhook: {
id: string;
url: string;
+ consecutiveFailures: number;
};
}) {
return (
@@ -54,8 +57,9 @@ export default function WebhookFailed({
Webhook is failing to deliver
</Heading>
<Text className="text-sm leading-6 text-black">
- Your webhook <strong>{webhook.url}</strong> is encountering
- delivery failures and will be disabled if it continues to fail.
+ Your webhook <strong>{webhook.url}</strong> has failed to deliver{" "}
+ {webhook.consecutiveFailures} times and will be disabled after{" "}
+ {WEBHOOK_FAILURE_DISABLE_THRESHOLD} consecutive failures.
</Text>
<Text className="text-sm leading-6 text-black">
Please review the webhook details and update the URL if necessary
diff --git a/apps/web/lib/webhook/failure.ts b/apps/web/lib/webhook/failure.ts
index 74f45de4dc..6faa13a5bb 100644
--- a/apps/web/lib/webhook/failure.ts
+++ b/apps/web/lib/webhook/failure.ts
@@ -80,7 +80,7 @@ export const resetWebhookFailureCount = async (webhookId: string) => {
// Send email to workspace owners when the webhook is failing to deliver
const notifyWebhookFailure = async (
- webhook: Pick<Webhook, "id" | "url" | "projectId">,
+ webhook: Pick<Webhook, "id" | "url" | "projectId" | "consecutiveFailures">,
) => {
const workspaceOwners = await prisma.projectUsers.findFirst({
where: { projectId: webhook.projectId, role: "owner" },
@@ -118,6 +118,7 @@ const notifyWebhookFailure = async (
webhook: {
id: webhook.id,
url: webhook.url,
+ consecutiveFailures: webhook.consecutiveFailures,
},
}),
});