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.

improve webhook response

Steven Teyd69823e4a719
diff --git a/apps/web/app/(ee)/api/appsflyer/webhook/route.ts b/apps/web/app/(ee)/api/appsflyer/webhook/route.ts
index c48e5c793c..996b138270 100644
--- a/apps/web/app/(ee)/api/appsflyer/webhook/route.ts
+++ b/apps/web/app/(ee)/api/appsflyer/webhook/route.ts
@@ -14,8 +14,8 @@ import { prisma } from "@dub/prisma";
import { Project } from "@dub/prisma/client";
import { APPSFLYER_INTEGRATION_ID, getSearchParams } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
-import { NextResponse } from "next/server";
import * as z from "zod/v4";
+import { logAndRespond } from "../../cron/utils";
const querySchema = z.object({
appId: z.string(),
@@ -53,7 +53,7 @@ export const GET = withAxiom(async (req) => {
const { appId, partnerEventId } = querySchema.parse(queryParams);
if (!partnerEventId || !["lead", "sale"].includes(partnerEventId)) {
- return NextResponse.json(
+ return logAndRespond(
`"${partnerEventId}" is not a valid partner event ID (accepted values: "lead", "sale"). Skipping...`,
);
}
@@ -81,7 +81,7 @@ export const GET = withAxiom(async (req) => {
if (!installation) {
throw new DubApiError({
code: "bad_request",
- message: "AppsFlyer integration is not configured for this app.",
+ message: `AppsFlyer integration is not configured for the appId: "${appId}". Did you add the app ID to the AppsFlyer integration settings?`,
});
}
@@ -98,7 +98,7 @@ export const GET = withAxiom(async (req) => {
customerAvatar,
} = trackLeadRequestSchema.parse(queryParams);
- await trackLead({
+ const leadResponse = await trackLead({
clickId,
eventName,
customerExternalId,
@@ -111,7 +111,7 @@ export const GET = withAxiom(async (req) => {
workspace,
});
- response = "Lead event tracked successfully.";
+ response = JSON.stringify(leadResponse);
}
// Track sale event
@@ -123,7 +123,7 @@ export const GET = withAxiom(async (req) => {
...(amountInCents !== undefined && { amount: amountInCents }),
});
- await trackSale({
+ const saleResponse = await trackSale({
customerExternalId,
amount,
currency,
@@ -135,7 +135,7 @@ export const GET = withAxiom(async (req) => {
workspace,
});
- response = "Sale event tracked successfully.";
+ response = JSON.stringify(saleResponse);
}
waitUntil(
@@ -151,7 +151,7 @@ export const GET = withAxiom(async (req) => {
}),
);
- return NextResponse.json(response);
+ return logAndRespond(response);
} catch (error) {
const errorResponse = handleAndReturnErrorResponse(error);