From 05ba22d3804407abc023cb2e1baad5509d218a13 Mon Sep 17 00:00:00 2001 From: pheralb Date: Sun, 31 Mar 2024 23:21:21 +0100 Subject: [PATCH] Trying to fix error handling on dashboard --- src/app/dashboard/page.tsx | 4 ++++ src/server/queries/index.ts | 29 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 950a2a6..656e341 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -26,6 +26,10 @@ const DashboardPage = async ({ const searchLink = searchParams?.search; const searchTag = searchParams?.tag; + if (!data) { + return
Error
; + } + if (!data?.links) { return
Error
; } diff --git a/src/server/queries/index.ts b/src/server/queries/index.ts index 889bd01..ce88717 100644 --- a/src/server/queries/index.ts +++ b/src/server/queries/index.ts @@ -14,27 +14,32 @@ export const getLinksAndTagsByUser = cache(async () => { return null; } - const [linksData, tagsData] = await db.$transaction([ - db.links.findMany({ + try { + + const linkData = await db.links.findMany({ where: { creatorId: currentUser.user?.id, }, include: { tags: true, }, - }), - db.tags.findMany({ + }); + + const tagsData = await db.tags.findMany({ where: { creatorId: currentUser.user?.id, }, - }), - ]); - - return { - limit: currentUser.user?.limitLinks, - links: linksData, - tags: tagsData, - }; + }); + + return { + limit: currentUser.user?.limitLinks, + links: linkData, + tags: tagsData, + }; + } catch (error) { + console.error("🚧 Error while fetching links and tags:", error); + throw error; // Propaga el error para que el componente que llama pueda manejarlo adecuadamente + } }); /**