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.
This commit is contained in:
2024-12-02 17:32:49 +07:00
parent 4b5ccc4bb7
commit 542312b7d8
2 changed files with 6 additions and 6 deletions

View File

@@ -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,