fix: network error handling and build errors (#4088)
* Fixed API not throwing network errors * Fix onBuildError assigning wrong status for the components * Fix Network Error handling, making it call onBuildError * Fixed build stop not triggering the alert --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jordan Frazier <122494242+jordanrfrazier@users.noreply.github.com>
This commit is contained in:
parent
d42165c3ef
commit
b5e504b4dc
3 changed files with 31 additions and 21 deletions
|
|
@ -250,18 +250,19 @@ async function performStreamingRequest({
|
||||||
}
|
}
|
||||||
let current: string[] = [];
|
let current: string[] = [];
|
||||||
let textDecoder = new TextDecoder();
|
let textDecoder = new TextDecoder();
|
||||||
|
|
||||||
|
try {
|
||||||
const response = await fetch(url, params);
|
const response = await fetch(url, params);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (onError) {
|
if (onError) {
|
||||||
onError(response.status);
|
onError(response.status);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("error in streaming request");
|
throw new Error("Error in streaming request.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (response.body === null) {
|
if (response.body === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
|
|
|
||||||
|
|
@ -675,10 +675,11 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
get().setLockChat(false);
|
get().setLockChat(false);
|
||||||
},
|
},
|
||||||
onBuildError: (title: string, list: string[], elementList) => {
|
onBuildError: (title: string, list: string[], elementList) => {
|
||||||
const idList = elementList
|
const idList =
|
||||||
.map((element) => element.id)
|
(elementList
|
||||||
.filter(Boolean) as string[];
|
?.map((element) => element.id)
|
||||||
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILT);
|
.filter(Boolean) as string[]) ?? get().nodes.map((n) => n.id);
|
||||||
|
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.ERROR);
|
||||||
if (get().componentsToUpdate)
|
if (get().componentsToUpdate)
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title:
|
title:
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ type BuildVerticesParams = {
|
||||||
buildId: string,
|
buildId: string,
|
||||||
) => void; // Replace any with the actual type if it's not any
|
) => void; // Replace any with the actual type if it's not any
|
||||||
onBuildComplete?: (allNodesValid: boolean) => void;
|
onBuildComplete?: (allNodesValid: boolean) => void;
|
||||||
onBuildError?: (title, list, idList: VertexLayerElementType[]) => void;
|
onBuildError?: (title, list, idList?: VertexLayerElementType[]) => void;
|
||||||
onBuildStopped?: () => void;
|
onBuildStopped?: () => void;
|
||||||
onBuildStart?: (idList: VertexLayerElementType[]) => void;
|
onBuildStart?: (idList: VertexLayerElementType[]) => void;
|
||||||
onValidateNodes?: (nodes: string[]) => void;
|
onValidateNodes?: (nodes: string[]) => void;
|
||||||
|
|
@ -40,6 +40,7 @@ function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
|
||||||
results: {},
|
results: {},
|
||||||
outputs: {},
|
outputs: {},
|
||||||
messages: [],
|
messages: [],
|
||||||
|
logs: {},
|
||||||
inactive: true,
|
inactive: true,
|
||||||
};
|
};
|
||||||
let inactiveVertexData = {
|
let inactiveVertexData = {
|
||||||
|
|
@ -125,7 +126,7 @@ export async function buildFlowVerticesWithFallback(
|
||||||
try {
|
try {
|
||||||
return await buildFlowVertices(params);
|
return await buildFlowVertices(params);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e.message === "endpoint not available") {
|
if (e.message === "Endpoint not available") {
|
||||||
return await buildVertices(params);
|
return await buildVertices(params);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
|
|
@ -295,12 +296,19 @@ export async function buildFlowVertices({
|
||||||
},
|
},
|
||||||
onError: (statusCode) => {
|
onError: (statusCode) => {
|
||||||
if (statusCode === 404) {
|
if (statusCode === 404) {
|
||||||
throw new Error("endpoint not available");
|
throw new Error("Endpoint not available");
|
||||||
}
|
}
|
||||||
throw new Error("error in streaming request");
|
throw new Error("Error Building Component");
|
||||||
|
},
|
||||||
|
onNetworkError: (error: Error) => {
|
||||||
|
if (error.name === "AbortError") {
|
||||||
|
onBuildStopped && onBuildStopped();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue