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 to account for race conditions

Steven Teyd0fffac1cab0
diff --git a/apps/web/lib/middleware/bitly.ts b/apps/web/lib/middleware/bitly.ts
index acc6534ba3..fdcd7f0d62 100644
--- a/apps/web/lib/middleware/bitly.ts
+++ b/apps/web/lib/middleware/bitly.ts
@@ -61,35 +61,40 @@ export const importBitlyLink = async (shortKey: string) => {
console.log("[Bitly] Creating link", newLink);
- await conn.execute(
- "INSERT INTO Link (id, projectId, userId, domain, `key`, url, shortLink, archived, folderId, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- [
- newLink.id,
- newLink.projectId,
- newLink.userId,
- newLink.domain,
- newLink.key,
- newLink.url,
- newLink.shortLink,
- newLink.archived,
- newLink.folderId,
- newLink.createdAt,
- newLink.updatedAt,
- ],
- );
+ try {
+ await conn.execute(
+ "INSERT INTO Link (id, projectId, userId, domain, `key`, url, shortLink, archived, folderId, createdAt, updatedAt) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ [
+ newLink.id,
+ newLink.projectId,
+ newLink.userId,
+ newLink.domain,
+ newLink.key,
+ newLink.url,
+ newLink.shortLink,
+ newLink.archived,
+ newLink.folderId,
+ newLink.createdAt,
+ newLink.updatedAt,
+ ],
+ );
- // TODO: fetch tags
- waitUntil(
- recordLink({
- ...newLink,
- tenantId: null,
- programId: null,
- partnerId: null,
- tags: [],
- } as unknown as ExpandedLink),
- );
+ // TODO: fetch tags
+ waitUntil(
+ recordLink({
+ ...newLink,
+ tenantId: null,
+ programId: null,
+ partnerId: null,
+ tags: [],
+ } as unknown as ExpandedLink),
+ );
- return newLink as unknown as EdgeLinkProps;
+ return newLink as unknown as EdgeLinkProps;
+ } catch (error) {
+ console.error("[Bitly] Error creating link", error);
+ return null;
+ }
};
async function fetchBitlyLink({