mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Ensure status/error events are propagated to parent properly
This commit is contained in:
@@ -321,21 +321,30 @@ class Flow {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a status event from a node within this flow. If there are no Status
|
||||
* nodes within this flow, pass the request to the parent flow.
|
||||
* @param {[type]} node [description]
|
||||
* @param {[type]} statusMessage [description]
|
||||
* Handle a status event from a node within this flow.
|
||||
* @param {Node} node The original node that triggered the event
|
||||
* @param {Object} statusMessage The status object
|
||||
* @param {Node} reportingNode The node emitting the status event.
|
||||
* This could be a subflow instance node when the status
|
||||
* is being delegated up.
|
||||
* @param {boolean} muteStatus Whether to emit the status event
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
handleStatus(node,statusMessage) {
|
||||
events.emit("node-status",{
|
||||
id: node.id,
|
||||
status:statusMessage
|
||||
});
|
||||
handleStatus(node,statusMessage,reportingNode,muteStatus) {
|
||||
if (!reportingNode) {
|
||||
reportingNode = node;
|
||||
}
|
||||
if (!muteStatus) {
|
||||
events.emit("node-status",{
|
||||
id: node.id,
|
||||
status:statusMessage
|
||||
});
|
||||
}
|
||||
|
||||
let handled = false;
|
||||
|
||||
var handled = false;
|
||||
this.statusNodes.forEach(function(targetStatusNode) {
|
||||
if (targetStatusNode.scope && targetStatusNode.scope.indexOf(node.id) === -1) {
|
||||
if (targetStatusNode.scope && targetStatusNode.scope.indexOf(reportingNode.id) === -1) {
|
||||
return;
|
||||
}
|
||||
var message = {
|
||||
@@ -354,21 +363,22 @@ class Flow {
|
||||
targetStatusNode.receive(message);
|
||||
handled = true;
|
||||
});
|
||||
if (!handled) {
|
||||
// // Nothing in this flow handled the status - pass it to the parent
|
||||
this.parent.handleStatus(node,statusMessage);
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an error event from a node within this flow. If there are no Catch
|
||||
* nodes within this flow, pass the event to the parent flow.
|
||||
* @param {[type]} node [description]
|
||||
* @param {[type]} logMessage [description]
|
||||
* @param {[type]} msg [description]
|
||||
* @return {[type]} [description]
|
||||
* @param {[type]} node [description]
|
||||
* @param {[type]} logMessage [description]
|
||||
* @param {[type]} msg [description]
|
||||
* @param {[type]} reportingNode [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
handleError(node,logMessage,msg) {
|
||||
handleError(node,logMessage,msg,reportingNode) {
|
||||
if (!reportingNode) {
|
||||
reportingNode = node;
|
||||
}
|
||||
// console.log("HE",logMessage);
|
||||
var count = 1;
|
||||
if (msg && msg.hasOwnProperty("error") && msg.error !== null) {
|
||||
@@ -384,7 +394,7 @@ class Flow {
|
||||
}
|
||||
var handled = false;
|
||||
this.catchNodes.forEach(function(targetCatchNode) {
|
||||
if (targetCatchNode.scope && targetCatchNode.scope.indexOf(node.id) === -1) {
|
||||
if (targetCatchNode.scope && targetCatchNode.scope.indexOf(reportingNode.id) === -1) {
|
||||
return;
|
||||
}
|
||||
var errorMessage;
|
||||
@@ -411,10 +421,6 @@ class Flow {
|
||||
targetCatchNode.receive(errorMessage);
|
||||
handled = true;
|
||||
});
|
||||
if (!handled) {
|
||||
// Nothing in this flow handled the error - pass it to the parent
|
||||
handled = this.parent.handleError(node,logMessage);
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
|
@@ -191,6 +191,50 @@ class Subflow extends Flow {
|
||||
}
|
||||
super.start(diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a status event from a node within this flow.
|
||||
* @param {Node} node The original node that triggered the event
|
||||
* @param {Object} statusMessage The status object
|
||||
* @param {Node} reportingNode The node emitting the status event.
|
||||
* This could be a subflow instance node when the status
|
||||
* is being delegated up.
|
||||
* @param {boolean} muteStatus Whether to emit the status event
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
handleStatus(node,statusMessage,reportingNode,muteStatus) {
|
||||
let handled = super.handleStatus(node,statusMessage,reportingNode,muteStatus);
|
||||
if (!handled) {
|
||||
// No status node on this subflow caught the status message.
|
||||
// Pass up to the parent with this subflow's instance as the
|
||||
// reporting node
|
||||
handled = this.parent.handleStatus(node,statusMessage,this.node,true);
|
||||
}
|
||||
return handled;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an error event from a node within this flow. If there are no Catch
|
||||
* nodes within this flow, pass the event to the parent flow.
|
||||
* @param {[type]} node [description]
|
||||
* @param {[type]} logMessage [description]
|
||||
* @param {[type]} msg [description]
|
||||
* @param {[type]} reportingNode [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
handleError(node,logMessage,msg,reportingNode) {
|
||||
let handled = super.handleError(node,logMessage,msg,reportingNode);
|
||||
if (!handled) {
|
||||
// No catch node on this subflow caught the error message.
|
||||
// Pass up to the parent with the subflow's instance as the
|
||||
// reporting node.
|
||||
handled = this.parent.handleError(node,logMessage,msg,this.node);
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user