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:
@@ -160,8 +160,10 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
if (!ctx.http?.me?.id) throw new Error('User not found')
|
if (!ctx.http?.me?.id) throw new Error('User not found')
|
||||||
if (!args.documentId) throw new Error('Document id 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')
|
if (args.pageIndex === undefined || args.pageIndex === null) throw new Error('Page index not found')
|
||||||
const delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex)
|
let delta = null
|
||||||
if (!delta) throw new Error('Delta not found')
|
try {
|
||||||
|
delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex)
|
||||||
|
} catch (_error) {}
|
||||||
const totalPage = await this.minio.countDocumentPages(args.documentId)
|
const totalPage = await this.minio.countDocumentPages(args.documentId)
|
||||||
return {
|
return {
|
||||||
documentId: args.documentId,
|
documentId: args.documentId,
|
||||||
@@ -311,10 +313,7 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!document) throw new Error('Document not found')
|
if (!document) throw new Error('Document not found')
|
||||||
if (
|
if (!document.isPublic && !document.collaborators.some((c) => c.userId === ctx.http?.me?.id && c.writable))
|
||||||
!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')
|
throw new Error('User is not owner or collaborator of document')
|
||||||
return await this.prisma.document.update({
|
return await this.prisma.document.update({
|
||||||
...query,
|
...query,
|
||||||
|
|||||||
Reference in New Issue
Block a user