Skip to content

Commit

Permalink
Trying to fix error handling on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pheralb committed Mar 31, 2024
1 parent 11c27bb commit 05ba22d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const DashboardPage = async ({
const searchLink = searchParams?.search;
const searchTag = searchParams?.tag;

if (!data) {
return <div>Error</div>;
}

if (!data?.links) {
return <div>Error</div>;
}
Expand Down
29 changes: 17 additions & 12 deletions src/server/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});

/**
Expand Down

0 comments on commit 05ba22d

Please sign in to comment.