@@ -1457,6 +1457,10 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
14571457 }
14581458
14591459 private async doCheck ( args : PermissionCheckArgs ) {
1460+ if ( ! [ 'create' , 'read' , 'update' , 'delete' ] . includes ( args . operation ) ) {
1461+ throw prismaClientValidationError ( this . prisma , this . prismaModule , `Invalid "operation" ${ args . operation } ` ) ;
1462+ }
1463+
14601464 let constraint = this . policyUtils . getCheckerConstraint ( this . model , args . operation ) ;
14611465 if ( typeof constraint === 'boolean' ) {
14621466 return constraint ;
@@ -1472,14 +1476,20 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
14721476 }
14731477
14741478 if ( value === null ) {
1475- throw new Error ( `Using "null" as filter value is not supported yet` ) ;
1479+ throw prismaClientValidationError (
1480+ this . prisma ,
1481+ this . prismaModule ,
1482+ `Using "null" as filter value is not supported yet`
1483+ ) ;
14761484 }
14771485
14781486 const fieldInfo = requireField ( this . modelMeta , this . model , field ) ;
14791487
14801488 // relation and array fields are not supported
14811489 if ( fieldInfo . isDataModel || fieldInfo . isArray ) {
1482- throw new Error (
1490+ throw prismaClientValidationError (
1491+ this . prisma ,
1492+ this . prismaModule ,
14831493 `Providing filter for field "${ field } " is not supported. Only scalar fields are allowed.`
14841494 ) ;
14851495 }
@@ -1490,26 +1500,38 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
14901500 . with ( 'String' , ( ) => 'string' )
14911501 . with ( 'Boolean' , ( ) => 'boolean' )
14921502 . otherwise ( ( ) => {
1493- throw new Error (
1503+ throw prismaClientValidationError (
1504+ this . prisma ,
1505+ this . prismaModule ,
14941506 `Providing filter for field "${ field } " is not supported. Only number, string, and boolean fields are allowed.`
14951507 ) ;
14961508 } ) ;
14971509
14981510 // check value type
14991511 const valueType = typeof value ;
15001512 if ( valueType !== 'number' && valueType !== 'string' && valueType !== 'boolean' ) {
1501- throw new Error (
1513+ throw prismaClientValidationError (
1514+ this . prisma ,
1515+ this . prismaModule ,
15021516 `Invalid value type for field "${ field } ". Only number, string or boolean is allowed.`
15031517 ) ;
15041518 }
15051519
15061520 if ( fieldType !== valueType ) {
1507- throw new Error ( `Invalid value type for field "${ field } ". Expected "${ fieldType } ".` ) ;
1521+ throw prismaClientValidationError (
1522+ this . prisma ,
1523+ this . prismaModule ,
1524+ `Invalid value type for field "${ field } ". Expected "${ fieldType } ".`
1525+ ) ;
15081526 }
15091527
15101528 // check number validity
15111529 if ( typeof value === 'number' && ( ! Number . isInteger ( value ) || value < 0 ) ) {
1512- throw new Error ( `Invalid value for field "${ field } ". Only non-negative integers are allowed.` ) ;
1530+ throw prismaClientValidationError (
1531+ this . prisma ,
1532+ this . prismaModule ,
1533+ `Invalid value for field "${ field } ". Only non-negative integers are allowed.`
1534+ ) ;
15131535 }
15141536
15151537 // build a constraint
0 commit comments