From ac60ea1f5f70cd0d718cde5dc1cd2c5d5f437f4d Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Mon, 13 Feb 2023 13:09:57 +0100 Subject: [PATCH] documents detail page 404 handling --- apps/web/pages/documents/[id]/index.tsx | 6 ++++++ packages/lib/query/getDocument.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/web/pages/documents/[id]/index.tsx b/apps/web/pages/documents/[id]/index.tsx index 56e8e2989..c617258e4 100644 --- a/apps/web/pages/documents/[id]/index.tsx +++ b/apps/web/pages/documents/[id]/index.tsx @@ -131,6 +131,12 @@ export async function getServerSideProps(context: any) { // todo optimize querys // todo no intersection groups + if (!document) { + return { + notFound: true, + }; + } + return { props: { document: document, diff --git a/packages/lib/query/getDocument.ts b/packages/lib/query/getDocument.ts index f922f4c28..d19555f62 100644 --- a/packages/lib/query/getDocument.ts +++ b/packages/lib/query/getDocument.ts @@ -12,7 +12,7 @@ export const getDocument = async ( if (!documentId) Promise.reject("No documentId"); if (!req || !res) Promise.reject("No res or req"); - const document: PrismaDocument = await prisma.document.findFirstOrThrow({ + const document: PrismaDocument = await prisma.document.findFirst({ where: { id: documentId, userId: user.id,