mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
fix(entity-validator): improve error messaging
This commit is contained in:
parent
7d64a36867
commit
df0fe1c9be
@ -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: [],
|
||||
},
|
||||
|
||||
@ -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: [],
|
||||
},
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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: [],
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user