Browse Source

Throw an error when using the name of a non-existent collection.

collection-component
mohamedsalem401 2 years ago
parent
commit
4a22be0c0e
  1. 23
      packages/core/src/data_sources/model/collection_component/CollectionComponent.ts

23
packages/core/src/data_sources/model/collection_component/CollectionComponent.ts

@ -151,17 +151,18 @@ function resolveBlockValues(context: any, block: any): any {
const collectionItem = blockValue.collection_name
? context[blockValue.collection_name]
: innerMostCollectionItem;
if (!collectionItem) continue;
switch (blockValue.variable_type) {
case 'current_item':
clonedBlock[key] = blockValue.path
? resolvePathValue(collectionItem.current_item, blockValue.path)
: JSON.stringify(collectionItem.current_item);
break;
default:
clonedBlock[key] = collectionItem[blockValue.variable_type];
break;
if (!collectionItem) {
throw new Error(
`Collection not found: ${blockValue.collection_name || 'default collection'}`
);
}
if (blockValue.variable_type === 'current_item') {
clonedBlock[key] = blockValue.path
? resolvePathValue(collectionItem.current_item, blockValue.path)
: JSON.stringify(collectionItem.current_item);
} else {
clonedBlock[key] = collectionItem[blockValue.variable_type];
}
} else if (Array.isArray(blockValue)) {
// Resolve each item in the array

Loading…
Cancel
Save