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.

make sure body is a valid JSON

Steven Teyef2a4615bcc3
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index 06153c2749..ab38bfaac3 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -35,7 +35,16 @@ export const GET = withAuth(async ({ headers, searchParams, project }) => {
// POST /api/links – create a new link
export const POST = withAuth(
async ({ req, headers, session, project }) => {
- const body = createLinkBodySchema.parse(await req.json());
+ let bodyRaw;
+ try {
+ bodyRaw = await req.json();
+ } catch (error) {
+ throw new DubApiError({
+ code: "bad_request",
+ message: "Invalid body – body must be a valid JSON.",
+ });
+ }
+ const body = createLinkBodySchema.parse(bodyRaw);
if (!session) {
const ip = req.headers.get("x-forwarded-for") || LOCALHOST_IP;