diff --git a/packages/runtime/src/enhancements/policy/policy-utils.ts b/packages/runtime/src/enhancements/policy/policy-utils.ts index 02bfa2068..0b263d616 100644 --- a/packages/runtime/src/enhancements/policy/policy-utils.ts +++ b/packages/runtime/src/enhancements/policy/policy-utils.ts @@ -651,7 +651,7 @@ export class PolicyUtil extends QueryUtils { throw this.deniedByPolicy( model, operation, - `entity ${JSON.stringify(uniqueFilter)} failed policy check`, + `entity ${formatObject(uniqueFilter, false)} failed policy check`, CrudFailureReason.ACCESS_POLICY_VIOLATION ); } @@ -664,7 +664,7 @@ export class PolicyUtil extends QueryUtils { throw this.deniedByPolicy( model, 'update', - `entity ${JSON.stringify(uniqueFilter)} failed update policy check for field "${ + `entity ${formatObject(uniqueFilter, false)} failed update policy check for field "${ fieldUpdateGuard.rejectedByField }"`, CrudFailureReason.ACCESS_POLICY_VIOLATION @@ -712,7 +712,7 @@ export class PolicyUtil extends QueryUtils { throw this.deniedByPolicy( model, operation, - `entity ${JSON.stringify(uniqueFilter)} failed policy check`, + `entity ${formatObject(uniqueFilter, false)} failed policy check`, CrudFailureReason.ACCESS_POLICY_VIOLATION ); } diff --git a/packages/runtime/src/enhancements/utils.ts b/packages/runtime/src/enhancements/utils.ts index 0e82e65be..92c8b7726 100644 --- a/packages/runtime/src/enhancements/utils.ts +++ b/packages/runtime/src/enhancements/utils.ts @@ -1,11 +1,13 @@ +import safeJsonStringify from 'safe-json-stringify'; import { FieldInfo, ModelMeta, resolveField } from '..'; import type { DbClientContract } from '../types'; /** * Formats an object for pretty printing. */ -export function formatObject(value: unknown) { - return JSON.stringify(value, undefined, 2); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function formatObject(value: any, multiLine = true) { + return multiLine ? safeJsonStringify(value, undefined, 2) : safeJsonStringify(value); } // eslint-disable-next-line @typescript-eslint/no-explicit-any