feat: log document id in ValidationError cause, if present

This commit is contained in:
Alessio Gravili
2024-08-21 17:31:31 -04:00
parent 5174c7092f
commit 9beaa281dc
3 changed files with 8 additions and 1 deletions

View File

@@ -351,6 +351,7 @@ export const upsertRow = async <T extends Record<string, unknown> | TypeWithID>(
throw error.code === '23505'
? new ValidationError(
{
id,
errors: [
{
field: adapter.fieldConstraints[tableName][error.constraint],

View File

@@ -21,7 +21,12 @@ export class ValidationError extends APIError<{
global?: string
}> {
constructor(
results: { collection?: string; errors: ValidationFieldError[]; global?: string },
results: {
collection?: string
errors: ValidationFieldError[]
global?: string
id?: number | string
},
t?: TFunction,
) {
const message = t

View File

@@ -71,6 +71,7 @@ export const beforeChange = async <T extends JsonObject>({
if (errors.length > 0) {
throw new ValidationError(
{
id,
collection: collection?.slug,
errors,
global: global?.slug,