Skip to content

Commit e033488

Browse files
authored
fix(nested-docs-plugin): throw an error to the UI if children are not passing validation (#7977)
1 parent 90b3e83 commit e033488

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/plugin-nested-docs/src/hooks/resaveChildren.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import type {
33
CollectionConfig,
44
JsonObject,
55
PayloadRequest,
6+
ValidationError,
67
} from 'payload'
78

9+
import { APIError } from 'payload'
10+
811
import type { NestedDocsPluginConfig } from '../types.js'
912

1013
import { populateBreadcrumbs } from '../utilities/populateBreadcrumbs.js'
@@ -69,6 +72,17 @@ const resave = async ({ collection, doc, draft, pluginConfig, req }: ResaveArgs)
6972
}.`,
7073
)
7174
req.payload.logger.error(err)
75+
76+
// Use type assertion until we can use instanceof reliably with our Error types
77+
if (
78+
(err as ValidationError)?.name === 'ValidationError' &&
79+
(err as ValidationError)?.data?.errors?.length
80+
) {
81+
throw new APIError(
82+
'Could not publish or save changes: One or more children are invalid.',
83+
400,
84+
)
85+
}
7286
}
7387
}
7488

0 commit comments

Comments
 (0)