From c21cd93a347acf3474903f7beb3ea9cbedd6e1bb Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Tue, 12 Mar 2024 18:10:08 +0700 Subject: [PATCH 1/2] Add try catch to update user id --- src/stores/analytics.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/stores/analytics.ts b/src/stores/analytics.ts index c0e6aeff0..b2f7ae967 100644 --- a/src/stores/analytics.ts +++ b/src/stores/analytics.ts @@ -65,9 +65,13 @@ const useAnalyticsBase = create()((set, get) => { _updateUserId: async (address: string | undefined) => { const { amp } = get() if (address) { - const userId = await createUserId(address) - amp?.setUserId(userId) - set({ userId }) + try { + const userId = await createUserId(address) + amp?.setUserId(userId) + set({ userId }) + } catch (err) { + console.error('Error creating user id', err) + } } else { amp?.setUserId(undefined) set({ userId: undefined }) From dee3023fde68de05fa719167593ce59bc8399cae Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Tue, 12 Mar 2024 18:28:20 +0700 Subject: [PATCH 2/2] Add try catch to link metadata timeout --- src/pages/api/posts.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pages/api/posts.ts b/src/pages/api/posts.ts index ff381f669..55c4294a2 100644 --- a/src/pages/api/posts.ts +++ b/src/pages/api/posts.ts @@ -105,11 +105,13 @@ export async function getPostsServer(postIds: string[]): Promise { // link fetching itself has timeout of 20_000, but for data fetching, it faster timeout // if it needs more than 8s, the post fetching is not delayed, but it will still be fetched and put to redis // so that in the next fetch, it will have the correct data from the redis - setTimeout(() => { - throw new Error('Link metadata fetching timeout') - }, 8_000) - const metadata = await getLinkMetadata(link) - if (metadata) metadataMap[link] = metadata + try { + setTimeout(() => { + throw new Error('Link metadata fetching timeout') + }, 8_000) + const metadata = await getLinkMetadata(link) + if (metadata) metadataMap[link] = metadata + } catch {} }) await Promise.allSettled(metadataPromises)