Skip to content

Commit

Permalink
Merge pull request #64 from entando/ENG-2553-add-path-check-and-catch…
Browse files Browse the repository at this point in the history
…-errors

ENG-2553 Add path check add catch errors and ootb ContentTypes reduce check
  • Loading branch information
alepintus authored Sep 15, 2021
2 parents fb4aaca + e391d4b commit c395d16
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions lib/env-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,21 @@ const componentResponseProcessor = {
}
}
};
const ootbContentTypesWithoutJacmsRole = contentType

const intermediate = contentType
.filter(filterOotbContentTypes) // get ootb contentTypes
.map(hasContentTypeAttrTitleAndNoJacmsRole) // check is at least one has an attribute with code === title and no jacms role
.reduce((first, second) => first || second); // at least one is true
if (ootbContentTypesWithoutJacmsRole) {
// export again
contentType = await Promise.all(componentsToFetch.map(getContentTypeDetail));
.map(hasContentTypeAttrTitleAndNoJacmsRole); // check is at least one has an attribute with code === title and no jacms role

// Make sure we have something to reduce
if (intermediate.length > 0) {
const ootbContentTypesWithoutJacmsRole = intermediate
.reduce((first, second) => first || second); // at least one is true
if (ootbContentTypesWithoutJacmsRole) {
// export again
contentType = await Promise.all(componentsToFetch.map(getContentTypeDetail));
}
}

// ### CODE WITH WORKAROUND - END ###
// ### CODE WITHOUT WORKAROUND - START ###
// const contentTypes = await Promise.all(componentsToFetch.map(async (contentType) => {
Expand Down Expand Up @@ -844,11 +851,21 @@ async function recursiveTraverseFileTree(root, token) {
return traversed.flat();
} else {
console.log('Collecting File: ' + resource.path);
const response = await axios.get(apiUrlTable.resourceDetails.replace('{path}', resource.path), {
headers: { Authorization: `Bearer ${token}` },
});

return response.data.payload;
if (resource.path.endsWith('/')) {
console.log('Skipping malformed path: ' + resource.path)
return {};
}
try {
const response = await axios.get(apiUrlTable.resourceDetails.replace('{path}', resource.path), {
headers: { Authorization: `Bearer ${token}` },
});
return response.data.payload;
} catch (error) {
console.log('Failed to get:', resource.path, error.config.url);
throw (error);
};

}
}));

Expand Down

0 comments on commit c395d16

Please sign in to comment.