🐛 fix(buildUtils.ts): refactor buildVertices function to improve readability and error handling
The buildVertices function has been refactored to improve readability and error handling. Instead of using Promise.all with map, it now uses a for loop to iterate over the vertices and perform the build process for each vertex. This change allows for better error handling and reporting. Additionally, the onBuildError callback is now called with the correct parameters when there is an error building a component.
This commit is contained in:
parent
cb284b4b7f
commit
b4dbe90212
1 changed files with 23 additions and 31 deletions
|
|
@ -52,42 +52,34 @@ export async function buildVertices({
|
|||
const buildResults: Array<boolean> = [];
|
||||
for (let i = 0; i < vertices.length; i += 1) {
|
||||
if (onBuildStart) onBuildStart(vertices[i]);
|
||||
await Promise.all(
|
||||
vertices[i].map(async (id) => {
|
||||
try {
|
||||
// Set vertex state to building
|
||||
const buildRes = await postBuildVertex(flowId, id);
|
||||
const buildData: VertexBuildTypeAPI = buildRes.data;
|
||||
if (onBuildUpdate) {
|
||||
let data = {};
|
||||
if (!buildData.valid) {
|
||||
if (onBuildError) {
|
||||
onBuildError(
|
||||
"Error Building Component",
|
||||
[buildData.params],
|
||||
verticesIds
|
||||
);
|
||||
}
|
||||
}
|
||||
data[buildData.id] = buildData;
|
||||
onBuildUpdate({ data, id: buildData.id });
|
||||
}
|
||||
buildResults.push(buildData.valid);
|
||||
} catch (error) {
|
||||
if (onBuildError) {
|
||||
console.log(error);
|
||||
onBuildError(
|
||||
for (const id of vertices[i]) {
|
||||
try {
|
||||
const buildRes = await postBuildVertex(flowId, id);
|
||||
const buildData: VertexBuildTypeAPI = buildRes.data;
|
||||
if (onBuildUpdate) {
|
||||
let data = {};
|
||||
if (!buildData.valid) {
|
||||
onBuildError!(
|
||||
"Error Building Component",
|
||||
[
|
||||
(error as AxiosError<any>).response?.data?.detail ??
|
||||
"Unknown Error",
|
||||
],
|
||||
[buildData.params],
|
||||
verticesIds
|
||||
);
|
||||
}
|
||||
data[buildData.id] = buildData;
|
||||
onBuildUpdate({ data, id: buildData.id });
|
||||
}
|
||||
})
|
||||
);
|
||||
buildResults.push(buildData.valid);
|
||||
} catch (error) {
|
||||
onBuildError!(
|
||||
"Error Building Component",
|
||||
[
|
||||
(error as AxiosError<any>).response?.data?.detail ??
|
||||
"Unknown Error",
|
||||
],
|
||||
verticesIds
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (onBuildComplete) {
|
||||
const allNodesValid = buildResults.every((result) => result);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue