fix(entity-validator): improve error messaging

This commit is contained in:
Jamie Howard 2022-11-23 14:32:26 +00:00
parent 7d64a36867
commit df0fe1c9be
4 changed files with 44 additions and 33 deletions

View File

@ -280,7 +280,8 @@ describe('CM API - Basic + dz + draftAndPublish', () => {
name: 'ValidationError',
},
{
message: 'Cannot build relations store: "uid" is undefined',
message:
'Cannot build relations store from dynamiczone, component identifier is undefined',
name: 'ValidationError',
path: [],
},

View File

@ -310,7 +310,8 @@ describe('CM API - Basic + dz', () => {
name: 'ValidationError',
},
{
message: 'Cannot build relations store: "uid" is undefined',
message:
'Cannot build relations store from dynamiczone, component identifier is undefined',
name: 'ValidationError',
path: [],
},

View File

@ -293,40 +293,48 @@ const buildRelationsStore = ({ uid, data }) => {
break;
}
case 'component': {
return castArray(value).reduce(
(relationsStore, componentValue) =>
mergeWith(
relationsStore,
buildRelationsStore({
uid: attribute.component,
data: componentValue,
}),
(objValue, srcValue) => {
if (isArray(objValue)) {
return objValue.concat(srcValue);
}
return castArray(value).reduce((relationsStore, componentValue) => {
if (!attribute.component) {
throw new ValidationError(
`Cannot build relations store from component, component identifier is undefined`
);
}
return mergeWith(
relationsStore,
buildRelationsStore({
uid: attribute.component,
data: componentValue,
}),
(objValue, srcValue) => {
if (isArray(objValue)) {
return objValue.concat(srcValue);
}
),
result
);
}
);
}, result);
}
case 'dynamiczone': {
return value.reduce(
(relationsStore, dzValue) =>
mergeWith(
relationsStore,
buildRelationsStore({
uid: dzValue.__component,
data: dzValue,
}),
(objValue, srcValue) => {
if (isArray(objValue)) {
return objValue.concat(srcValue);
}
return value.reduce((relationsStore, dzValue) => {
if (!dzValue.__component) {
throw new ValidationError(
`Cannot build relations store from dynamiczone, component identifier is undefined`
);
}
return mergeWith(
relationsStore,
buildRelationsStore({
uid: dzValue.__component,
data: dzValue,
}),
(objValue, srcValue) => {
if (isArray(objValue)) {
return objValue.concat(srcValue);
}
),
result
);
}
);
}, result);
}
default:
break;

View File

@ -350,7 +350,8 @@ describe('Core API - Basic + dz', () => {
name: 'ValidationError',
},
{
message: 'Cannot build relations store: "uid" is undefined',
message:
'Cannot build relations store from dynamiczone, component identifier is undefined',
name: 'ValidationError',
path: [],
},