Refactor buildVertices function to improve readability and error handling
This commit is contained in:
parent
e6b8cf551b
commit
411060af93
1 changed files with 34 additions and 31 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import { getVerticesOrder, postBuildVertex } from "../controllers/API";
|
import { getVerticesOrder, postBuildVertex } from "../controllers/API";
|
||||||
import { FlowType } from "../types/flow";
|
|
||||||
import { VertexBuildTypeAPI } from "../types/api";
|
import { VertexBuildTypeAPI } from "../types/api";
|
||||||
|
import { FlowType } from "../types/flow";
|
||||||
|
|
||||||
type BuildVerticesParams = {
|
type BuildVerticesParams = {
|
||||||
flow: FlowType; // Assuming FlowType is the type for your flow
|
flow: FlowType; // Assuming FlowType is the type for your flow
|
||||||
|
|
@ -22,7 +22,7 @@ export async function buildVertices({
|
||||||
}: BuildVerticesParams) {
|
}: BuildVerticesParams) {
|
||||||
let orderResponse = await getVerticesOrder(flow.id);
|
let orderResponse = await getVerticesOrder(flow.id);
|
||||||
let verticesOrder: Array<Array<string>> = orderResponse.data.ids;
|
let verticesOrder: Array<Array<string>> = orderResponse.data.ids;
|
||||||
let vertices : Array<Array<string>> = [];
|
let vertices: Array<Array<string>> = [];
|
||||||
if (nodeId) {
|
if (nodeId) {
|
||||||
for (let i = 0; i < verticesOrder.length; i += 1) {
|
for (let i = 0; i < verticesOrder.length; i += 1) {
|
||||||
const innerArray = verticesOrder[i];
|
const innerArray = verticesOrder[i];
|
||||||
|
|
@ -49,7 +49,7 @@ export async function buildVertices({
|
||||||
let data = {};
|
let data = {};
|
||||||
if (!buildData.valid) {
|
if (!buildData.valid) {
|
||||||
if (onBuildError) {
|
if (onBuildError) {
|
||||||
onBuildError("Error Building Component", [buildData.params])
|
onBuildError("Error Building Component", [buildData.params]);
|
||||||
}
|
}
|
||||||
data[buildData.id] = buildData;
|
data[buildData.id] = buildData;
|
||||||
|
|
||||||
|
|
@ -63,11 +63,14 @@ export async function buildVertices({
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (onBuildError) {
|
if (onBuildError) {
|
||||||
console.log(error)
|
console.log(error);
|
||||||
onBuildError("Error Building Component", [(error as AxiosError<any>).response?.data?.detail??"Unknown Error"]);
|
onBuildError("Error Building Component", [
|
||||||
|
(error as AxiosError<any>).response?.data?.detail ??
|
||||||
|
"Unknown Error",
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue