mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Propagate Status/Error events from global config nodes
This commit is contained in:
parent
c99b35428b
commit
4baaaa8d59
@ -322,19 +322,19 @@ class Flow {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a status event from a node within this flow.
|
* Handle a status event from a node within this flow.
|
||||||
* @param {Node} node The original node that triggered the event
|
* @param {Node} node The original node that triggered the event
|
||||||
* @param {Object} statusMessage The status object
|
* @param {Object} statusMessage The status object
|
||||||
* @param {Node} reportingNode The node emitting the status event.
|
* @param {Node} reportingNode The node emitting the status event.
|
||||||
* This could be a subflow instance node when the status
|
* This could be a subflow instance node when the status
|
||||||
* is being delegated up.
|
* is being delegated up.
|
||||||
* @param {boolean} muteStatus Whether to emit the status event
|
* @param {boolean} muteStatusEvent Whether to emit the status event
|
||||||
* @return {[type]} [description]
|
* @return {[type]} [description]
|
||||||
*/
|
*/
|
||||||
handleStatus(node,statusMessage,reportingNode,muteStatus) {
|
handleStatus(node,statusMessage,reportingNode,muteStatusEvent) {
|
||||||
if (!reportingNode) {
|
if (!reportingNode) {
|
||||||
reportingNode = node;
|
reportingNode = node;
|
||||||
}
|
}
|
||||||
if (!muteStatus) {
|
if (!muteStatusEvent) {
|
||||||
events.emit("node-status",{
|
events.emit("node-status",{
|
||||||
id: node.id,
|
id: node.id,
|
||||||
status:statusMessage
|
status:statusMessage
|
||||||
@ -343,26 +343,37 @@ class Flow {
|
|||||||
|
|
||||||
let handled = false;
|
let handled = false;
|
||||||
|
|
||||||
this.statusNodes.forEach(function(targetStatusNode) {
|
if (this.id === 'global' && node.users) {
|
||||||
if (targetStatusNode.scope && targetStatusNode.scope.indexOf(reportingNode.id) === -1) {
|
// This is a global config node
|
||||||
return;
|
// Delegate status to any nodes using this config node
|
||||||
}
|
for (let userNode in node.users) {
|
||||||
var message = {
|
if (node.users.hasOwnProperty(userNode)) {
|
||||||
status: {
|
node.users[userNode]._flow.handleStatus(node,statusMessage,node.users[userNode],true);
|
||||||
text: "",
|
|
||||||
source: {
|
|
||||||
id: node.id,
|
|
||||||
type: node.type,
|
|
||||||
name: node.name
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
if (statusMessage.hasOwnProperty("text")) {
|
|
||||||
message.status.text = statusMessage.text.toString();
|
|
||||||
}
|
}
|
||||||
targetStatusNode.receive(message);
|
|
||||||
handled = true;
|
handled = true;
|
||||||
});
|
} else {
|
||||||
|
this.statusNodes.forEach(function(targetStatusNode) {
|
||||||
|
if (targetStatusNode.scope && targetStatusNode.scope.indexOf(reportingNode.id) === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var message = {
|
||||||
|
status: {
|
||||||
|
text: "",
|
||||||
|
source: {
|
||||||
|
id: node.id,
|
||||||
|
type: node.type,
|
||||||
|
name: node.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (statusMessage.hasOwnProperty("text")) {
|
||||||
|
message.status.text = statusMessage.text.toString();
|
||||||
|
}
|
||||||
|
targetStatusNode.receive(message);
|
||||||
|
handled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,35 +403,47 @@ class Flow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var handled = false;
|
let handled = false;
|
||||||
this.catchNodes.forEach(function(targetCatchNode) {
|
|
||||||
if (targetCatchNode.scope && targetCatchNode.scope.indexOf(reportingNode.id) === -1) {
|
if (this.id === 'global' && node.users) {
|
||||||
return;
|
// This is a global config node
|
||||||
}
|
// Delegate status to any nodes using this config node
|
||||||
var errorMessage;
|
for (let userNode in node.users) {
|
||||||
if (msg) {
|
if (node.users.hasOwnProperty(userNode)) {
|
||||||
errorMessage = redUtil.cloneMessage(msg);
|
node.users[userNode]._flow.handleError(node,logMessage,msg,node.users[userNode]);
|
||||||
} else {
|
|
||||||
errorMessage = {};
|
|
||||||
}
|
|
||||||
if (errorMessage.hasOwnProperty("error")) {
|
|
||||||
errorMessage._error = errorMessage.error;
|
|
||||||
}
|
|
||||||
errorMessage.error = {
|
|
||||||
message: logMessage.toString(),
|
|
||||||
source: {
|
|
||||||
id: node.id,
|
|
||||||
type: node.type,
|
|
||||||
name: node.name,
|
|
||||||
count: count
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
if (logMessage.hasOwnProperty('stack')) {
|
|
||||||
errorMessage.error.stack = logMessage.stack;
|
|
||||||
}
|
}
|
||||||
targetCatchNode.receive(errorMessage);
|
|
||||||
handled = true;
|
handled = true;
|
||||||
});
|
} else {
|
||||||
|
this.catchNodes.forEach(function(targetCatchNode) {
|
||||||
|
if (targetCatchNode.scope && targetCatchNode.scope.indexOf(reportingNode.id) === -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var errorMessage;
|
||||||
|
if (msg) {
|
||||||
|
errorMessage = redUtil.cloneMessage(msg);
|
||||||
|
} else {
|
||||||
|
errorMessage = {};
|
||||||
|
}
|
||||||
|
if (errorMessage.hasOwnProperty("error")) {
|
||||||
|
errorMessage._error = errorMessage.error;
|
||||||
|
}
|
||||||
|
errorMessage.error = {
|
||||||
|
message: logMessage.toString(),
|
||||||
|
source: {
|
||||||
|
id: node.id,
|
||||||
|
type: node.type,
|
||||||
|
name: node.name,
|
||||||
|
count: count
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (logMessage.hasOwnProperty('stack')) {
|
||||||
|
errorMessage.error.stack = logMessage.stack;
|
||||||
|
}
|
||||||
|
targetCatchNode.receive(errorMessage);
|
||||||
|
handled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user