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.

adjust the hooks sending

Kiran K8944cdb177cd
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index c0083c5fec..195e845089 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -2,6 +2,7 @@ import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import { createLink, getLinksForWorkspace, processLink } from "@/lib/api/links";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
+import { prisma } from "@/lib/prisma";
import { ratelimit } from "@/lib/upstash";
import {
createLinkBodySchema,
@@ -81,14 +82,27 @@ export const POST = withWorkspace(
try {
const response = await createLink(link);
- if (workspace.zapierWebhookUrl) {
- await fetch(workspace.zapierWebhookUrl, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
+ // TODO: Send this via Redis queue
+ if (workspace) {
+ const hooks = await prisma.zapierHook.findMany({
+ where: {
+ projectId: workspace.id,
},
- body: JSON.stringify(response),
});
+
+ if (hooks.length) {
+ for (const hook of hooks) {
+ const responseHook = await fetch(hook.url, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(response),
+ });
+
+ console.log({ url: hook.url, status: responseHook.status });
+ }
+ }
}
return NextResponse.json(response, { headers });
diff --git a/apps/web/lib/api/errors.ts b/apps/web/lib/api/errors.ts
index 0f69d2f734..7161a6aa20 100644
--- a/apps/web/lib/api/errors.ts
+++ b/apps/web/lib/api/errors.ts
@@ -118,7 +118,7 @@ export function fromZodError(error: ZodError): ErrorResponse {
}
export function handleApiError(error: any): ErrorResponse & { status: number } {
- console.error("API error occurred", error, JSON.stringify(error, null, 2));
+ //console.error("API error occurred", error, JSON.stringify(error, null, 2));
// Zod errors
if (error instanceof ZodError) {