Refactor buildVertices function to improve readability and error handling

This commit is contained in:
anovazzi1 2024-01-22 15:55:21 -03:00
commit 411060af93

View file

@ -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
@ -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",
]);
} }
} }
}) })
) );
} }
} }