@@ -28,6 +28,7 @@ export type GlobalFindOneArgs = {
2828 */
2929 data ?: Record < string , unknown >
3030 depth ?: number
31+ disableErrors ?: boolean
3132 draft ?: boolean
3233 globalConfig : SanitizedGlobalConfig
3334 includeLockStatus ?: boolean
@@ -45,6 +46,7 @@ export const findOneOperation = async <T extends Record<string, unknown>>(
4546 const {
4647 slug,
4748 depth,
49+ disableErrors,
4850 draft : replaceWithVersion = false ,
4951 flattenLocales,
5052 globalConfig,
@@ -86,11 +88,14 @@ export const findOneOperation = async <T extends Record<string, unknown>>(
8688 let accessResult ! : AccessResult
8789
8890 if ( ! overrideAccess ) {
89- accessResult = await executeAccess ( { req } , globalConfig . access . read )
91+ accessResult = await executeAccess ( { disableErrors , req } , globalConfig . access . read )
9092 }
9193
9294 if ( accessResult === false ) {
93- throw new NotFound ( req . t )
95+ if ( ! disableErrors ) {
96+ throw new NotFound ( req . t )
97+ }
98+ return null !
9499 }
95100
96101 const select = sanitizeSelect ( {
@@ -125,7 +130,10 @@ export const findOneOperation = async <T extends Record<string, unknown>>(
125130 const hasDoc = docFromDB && Object . keys ( docFromDB ) . length > 0
126131
127132 if ( ! hasDoc && ! args . data && ! overrideAccess && accessResult !== true ) {
128- return { } as any
133+ if ( ! disableErrors ) {
134+ return { } as any
135+ }
136+ return null !
129137 }
130138
131139 let doc = ( args . data as any ) ?? ( hasDoc ? docFromDB : null ) ?? { }
0 commit comments