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.

add try catch for invite created

Steven Tey77112dd3f1e6
diff --git a/apps/web/app/app.dub.co/(auth)/invites/[code]/page.tsx b/apps/web/app/app.dub.co/(auth)/invites/[code]/page.tsx
index 49fa154e67..df2845a17d 100644
--- a/apps/web/app/app.dub.co/(auth)/invites/[code]/page.tsx
+++ b/apps/web/app/app.dub.co/(auth)/invites/[code]/page.tsx
@@ -81,13 +81,24 @@ async function VerifyInvite({ code }: { code: string }) {
);
}
- await prisma.projectInvite.create({
- data: {
- email: session.user.email,
- expires: new Date(Date.now() + TWO_WEEKS_IN_SECONDS * 1000),
- projectId: project.id,
- },
- });
+ try {
+ await prisma.projectInvite.create({
+ data: {
+ email: session.user.email,
+ expires: new Date(Date.now() + TWO_WEEKS_IN_SECONDS * 1000),
+ projectId: project.id,
+ },
+ });
+ } catch (e) {
+ if (e.code !== "P2002") {
+ return (
+ <>
+ <h1 className="font-display text-4xl font-bold">Error</h1>
+ <p className="text-lg text-gray-600">{e.message}</p>
+ </>
+ );
+ }
+ }
redirect(`/${project.slug}`);
}
diff --git a/apps/web/scripts/seed-invite-codes.ts b/apps/web/scripts/seed-invite-codes.ts
index fcf8b878e0..1ab978e1ff 100644
--- a/apps/web/scripts/seed-invite-codes.ts
+++ b/apps/web/scripts/seed-invite-codes.ts
@@ -10,7 +10,7 @@ async function main() {
where: {
inviteCode: null,
},
- take: 1000,
+ take: 500,
});
const res = await Promise.all(