added try catch block on streamNodeData

This commit is contained in:
anovazzi1 2023-06-13 18:45:42 -03:00
commit 86751e0daf

View file

@ -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) => {
// If the event is parseable, return
if (!event.data) {
return;
}
const parsedData = JSON.parse(event.data);
// if the event is the end of the stream, close the connection
if (parsedData.end_of_stream) {
eventSource.close();
eventSource.onmessage = (event) => { return;
// If the event is parseable, return }
if (!event.data) { // Otherwise, process the data
return; const isValid = processStreamResult(parsedData);
} validationResults.push(isValid);
const parsedData = JSON.parse(event.data); };
// if the event is the end of the stream, close the connection
if (parsedData.end_of_stream) { 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) {