@@ -25,6 +25,7 @@ export type GlobalFindOneArgs = {
2525 */
2626 data ?: Record < string , unknown >
2727 depth ?: number
28+ disableErrors ?: boolean
2829 draft ?: boolean
2930 globalConfig : SanitizedGlobalConfig
3031 includeLockStatus ?: boolean
@@ -42,6 +43,7 @@ export const findOneOperation = async <T extends Record<string, unknown>>(
4243 const {
4344 slug,
4445 depth,
46+ disableErrors,
4547 draft : replaceWithVersion = false ,
4648 flattenLocales,
4749 globalConfig,
@@ -79,11 +81,14 @@ export const findOneOperation = async <T extends Record<string, unknown>>(
7981 let accessResult ! : AccessResult
8082
8183 if ( ! overrideAccess ) {
82- accessResult = await executeAccess ( { req } , globalConfig . access . read )
84+ accessResult = await executeAccess ( { disableErrors , req } , globalConfig . access . read )
8385 }
8486
8587 if ( accessResult === false ) {
86- throw new NotFound ( req . t )
88+ if ( ! disableErrors ) {
89+ throw new NotFound ( req . t )
90+ }
91+ return null !
8792 }
8893
8994 const select = sanitizeSelect ( {
@@ -108,7 +113,10 @@ export const findOneOperation = async <T extends Record<string, unknown>>(
108113 const hasDoc = docFromDB && Object . keys ( docFromDB ) . length > 0
109114
110115 if ( ! hasDoc && ! args . data && ! overrideAccess && accessResult !== true ) {
111- return { } as any
116+ if ( ! disableErrors ) {
117+ return { } as any
118+ }
119+ return null !
112120 }
113121
114122 let doc = ( args . data as any ) ?? ( hasDoc ? docFromDB : null ) ?? { }
0 commit comments