🐛 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,31 +52,25 @@ export async function buildVertices({
|
||||||
const buildResults: Array<boolean> = [];
|
const buildResults: Array<boolean> = [];
|
||||||
for (let i = 0; i < vertices.length; i += 1) {
|
for (let i = 0; i < vertices.length; i += 1) {
|
||||||
if (onBuildStart) onBuildStart(vertices[i]);
|
if (onBuildStart) onBuildStart(vertices[i]);
|
||||||
await Promise.all(
|
for (const id of vertices[i]) {
|
||||||
vertices[i].map(async (id) => {
|
|
||||||
try {
|
try {
|
||||||
// Set vertex state to building
|
|
||||||
const buildRes = await postBuildVertex(flowId, id);
|
const buildRes = await postBuildVertex(flowId, id);
|
||||||
const buildData: VertexBuildTypeAPI = buildRes.data;
|
const buildData: VertexBuildTypeAPI = buildRes.data;
|
||||||
if (onBuildUpdate) {
|
if (onBuildUpdate) {
|
||||||
let data = {};
|
let data = {};
|
||||||
if (!buildData.valid) {
|
if (!buildData.valid) {
|
||||||
if (onBuildError) {
|
onBuildError!(
|
||||||
onBuildError(
|
|
||||||
"Error Building Component",
|
"Error Building Component",
|
||||||
[buildData.params],
|
[buildData.params],
|
||||||
verticesIds
|
verticesIds
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
data[buildData.id] = buildData;
|
data[buildData.id] = buildData;
|
||||||
onBuildUpdate({ data, id: buildData.id });
|
onBuildUpdate({ data, id: buildData.id });
|
||||||
}
|
}
|
||||||
buildResults.push(buildData.valid);
|
buildResults.push(buildData.valid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (onBuildError) {
|
onBuildError!(
|
||||||
console.log(error);
|
|
||||||
onBuildError(
|
|
||||||
"Error Building Component",
|
"Error Building Component",
|
||||||
[
|
[
|
||||||
(error as AxiosError<any>).response?.data?.detail ??
|
(error as AxiosError<any>).response?.data?.detail ??
|
||||||
|
|
@ -86,8 +80,6 @@ export async function buildVertices({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (onBuildComplete) {
|
if (onBuildComplete) {
|
||||||
const allNodesValid = buildResults.every((result) => result);
|
const allNodesValid = buildResults.every((result) => result);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue