added try catch block on streamNodeData
This commit is contained in:
parent
d14be904ad
commit
86751e0daf
1 changed files with 32 additions and 26 deletions
|
|
@ -60,35 +60,41 @@ export default function BuildTrigger({
|
||||||
let finished = false;
|
let finished = false;
|
||||||
apiUrl = `/build/stream/${flowId}`;
|
apiUrl = `/build/stream/${flowId}`;
|
||||||
const eventSource = new EventSource(apiUrl);
|
const eventSource = new EventSource(apiUrl);
|
||||||
|
try{
|
||||||
eventSource.onmessage = (event) => {
|
eventSource.onmessage = (event) => {
|
||||||
// If the event is parseable, return
|
// If the event is parseable, return
|
||||||
if (!event.data) {
|
if (!event.data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const parsedData = JSON.parse(event.data);
|
const parsedData = JSON.parse(event.data);
|
||||||
// if the event is the end of the stream, close the connection
|
// if the event is the end of the stream, close the connection
|
||||||
if (parsedData.end_of_stream) {
|
if (parsedData.end_of_stream) {
|
||||||
|
eventSource.close();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Otherwise, process the data
|
||||||
|
const isValid = processStreamResult(parsedData);
|
||||||
|
validationResults.push(isValid);
|
||||||
|
};
|
||||||
|
|
||||||
|
eventSource.onerror = (error) => {
|
||||||
|
console.error("EventSource failed:", error);
|
||||||
eventSource.close();
|
eventSource.close();
|
||||||
|
};
|
||||||
return;
|
// Step 3: Wait for the stream to finish
|
||||||
|
while (!finished) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||||
|
finished = validationResults.length === flow.data.nodes.length;
|
||||||
}
|
}
|
||||||
// Otherwise, process the data
|
// Step 4: Return true if all nodes are valid, false otherwise
|
||||||
const isValid = processStreamResult(parsedData);
|
return validationResults.every((result) => result);
|
||||||
validationResults.push(isValid);
|
}
|
||||||
};
|
catch(e){
|
||||||
|
console.log(e)
|
||||||
eventSource.onerror = (error) => {
|
eventSource.close();
|
||||||
console.error("EventSource failed:", error);
|
return false;
|
||||||
eventSource.close();
|
|
||||||
};
|
|
||||||
// Step 3: Wait for the stream to finish
|
|
||||||
while (!finished) {
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
||||||
finished = validationResults.length === flow.data.nodes.length;
|
|
||||||
}
|
}
|
||||||
// Step 4: Return true if all nodes are valid, false otherwise
|
|
||||||
return validationResults.every((result) => result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function processStreamResult(parsedData) {
|
function processStreamResult(parsedData) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue