The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add try catch
Steven Teye7c91226e5f4
diff --git a/apps/web/lib/tinybird/get-click-event.ts b/apps/web/lib/tinybird/get-click-event.tsindex 032d323e7f..8f9e0a8a4f 100644--- a/apps/web/lib/tinybird/get-click-event.ts+++ b/apps/web/lib/tinybird/get-click-event.ts@@ -13,19 +13,21 @@ const getClickEventTB = tb.buildPipe({});export const getClickEvent = async ({ clickId }: { clickId: string }) => {- // check Redis cache first- const cachedClickData = await redis.get<ClickEventTB>(- `clickIdCache:${clickId}`,- );+ try {+ // check Redis cache first+ const cachedClickData = await redis.get<ClickEventTB>(+ `clickIdCache:${clickId}`,+ );- if (cachedClickData) {- return {- ...cachedClickData,- timestamp: cachedClickData.timestamp.replace("T", " ").replace("Z", ""),- qr: cachedClickData.qr ? 1 : 0,- bot: cachedClickData.bot ? 1 : 0,- };- }+ if (cachedClickData) {+ return {+ ...cachedClickData,+ timestamp: cachedClickData.timestamp.replace("T", " ").replace("Z", ""),+ qr: cachedClickData.qr ? 1 : 0,+ bot: cachedClickData.bot ? 1 : 0,+ };+ }+ } catch (_e) {}try {// fallback to Tinybird if Redis cache is not founddiff --git a/apps/web/lib/tinybird/get-lead-event.ts b/apps/web/lib/tinybird/get-lead-event.tsindex e9d57b5978..b2ae6f02e2 100644--- a/apps/web/lib/tinybird/get-lead-event.ts+++ b/apps/web/lib/tinybird/get-lead-event.ts@@ -20,15 +20,19 @@ export const getLeadEvent = async ({customerId: string;eventName?: string | null;}) => {- const cachedLeadEvent = await redis.get<LeadEventTB>(- `leadCache:${customerId}${eventName ? `:${eventName.toLowerCase().replaceAll(" ", "-")}` : ""}`,- );+ try {+ // check Redis cache first+ const cachedLeadEvent = await redis.get<LeadEventTB>(+ `leadCache:${customerId}${eventName ? `:${eventName.toLowerCase().replaceAll(" ", "-")}` : ""}`,+ );- if (cachedLeadEvent) {- return cachedLeadEvent;- }+ if (cachedLeadEvent) {+ return cachedLeadEvent;+ }+ } catch (_e) {}try {+ // fallback to Tinybird if Redis cache is not foundconst { data } = await getLeadEventTB({ customerId, eventName });return data[0];} catch (error) {