From 542312b7d84f821884067ad2e9857c6712a50b33 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Mon, 2 Dec 2024 17:32:49 +0700 Subject: [PATCH] fix: improve error handling in DocumentSchema for document page retrieval - Updated the document page retrieval logic to handle errors gracefully by using a try-catch block, preventing the application from throwing an error if the document page is not found. - Simplified the validation check for document ownership and collaboration access by consolidating conditions into a single line for better readability. --- .nvmrc | 1 + src/Document/document.schema.ts | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..fdb2eaa --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22.11.0 \ No newline at end of file diff --git a/src/Document/document.schema.ts b/src/Document/document.schema.ts index a8ea995..5ab8977 100644 --- a/src/Document/document.schema.ts +++ b/src/Document/document.schema.ts @@ -160,8 +160,10 @@ export class DocumentSchema extends PothosSchema { if (!ctx.http?.me?.id) throw new Error('User not found') if (!args.documentId) throw new Error('Document id not found') if (args.pageIndex === undefined || args.pageIndex === null) throw new Error('Page index not found') - const delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex) - if (!delta) throw new Error('Delta not found') + let delta = null + try { + delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex) + } catch (_error) {} const totalPage = await this.minio.countDocumentPages(args.documentId) return { documentId: args.documentId, @@ -311,10 +313,7 @@ export class DocumentSchema extends PothosSchema { }, }) if (!document) throw new Error('Document not found') - if ( - !document.isPublic && - !document.collaborators.some((c) => c.userId === ctx.http?.me?.id && c.writable) - ) + if (!document.isPublic && !document.collaborators.some((c) => c.userId === ctx.http?.me?.id && c.writable)) throw new Error('User is not owner or collaborator of document') return await this.prisma.document.update({ ...query,