Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: network error handling and build errors #4088

Merged
merged 9 commits into from
Oct 10, 2024
23 changes: 12 additions & 11 deletions src/frontend/src/controllers/API/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,19 @@ async function performStreamingRequest({
}
let current: string[] = [];
let textDecoder = new TextDecoder();
const response = await fetch(url, params);
if (!response.ok) {
if (onError) {
onError(response.status);
} else {
throw new Error("error in streaming request");
}
}
if (response.body === null) {
return;
}

try {
const response = await fetch(url, params);
if (!response.ok) {
if (onError) {
onError(response.status);
} else {
throw new Error("Error in streaming request.");
}
}
if (response.body === null) {
return;
}
const reader = response.body.getReader();
while (true) {
const { done, value } = await reader.read();
Expand Down
9 changes: 5 additions & 4 deletions src/frontend/src/stores/flowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,11 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
get().setLockChat(false);
},
onBuildError: (title: string, list: string[], elementList) => {
const idList = elementList
.map((element) => element.id)
.filter(Boolean) as string[];
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILT);
const idList =
(elementList
?.map((element) => element.id)
.filter(Boolean) as string[]) ?? get().nodes.map((n) => n.id);
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.ERROR);
if (get().componentsToUpdate)
setErrorData({
title:
Expand Down
20 changes: 14 additions & 6 deletions src/frontend/src/utils/buildUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type BuildVerticesParams = {
buildId: string,
) => void; // Replace any with the actual type if it's not any
onBuildComplete?: (allNodesValid: boolean) => void;
onBuildError?: (title, list, idList: VertexLayerElementType[]) => void;
onBuildError?: (title, list, idList?: VertexLayerElementType[]) => void;
onBuildStopped?: () => void;
onBuildStart?: (idList: VertexLayerElementType[]) => void;
onValidateNodes?: (nodes: string[]) => void;
Expand All @@ -40,6 +40,7 @@ function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
results: {},
outputs: {},
messages: [],
logs: {},
inactive: true,
};
let inactiveVertexData = {
Expand Down Expand Up @@ -125,7 +126,7 @@ export async function buildFlowVerticesWithFallback(
try {
return await buildFlowVertices(params);
} catch (e: any) {
if (e.message === "endpoint not available") {
if (e.message === "Endpoint not available") {
return await buildVertices(params);
}
throw e;
Expand Down Expand Up @@ -295,12 +296,19 @@ export async function buildFlowVertices({
},
onError: (statusCode) => {
if (statusCode === 404) {
throw new Error("endpoint not available");
throw new Error("Endpoint not available");
}
throw new Error("Error Building Component");
},
onNetworkError: (error: Error) => {
if (error.name === "AbortError") {
onBuildStopped && onBuildStopped();
return;
}
throw new Error("error in streaming request");
onBuildError!("Error Building Component", [
"Network error. Please check the connection to the server.",
]);
},
// network error are likely caused by the window.stop() called in the stopBuild function
onNetworkError: onBuildStopped,
});
}

Expand Down