diff --git a/nodes/core/core/25-catch.html b/nodes/core/core/25-catch.html
new file mode 100644
index 000000000..4610d2e40
--- /dev/null
+++ b/nodes/core/core/25-catch.html
@@ -0,0 +1,44 @@
+
+
+
+
+
+
diff --git a/nodes/core/core/25-catch.js b/nodes/core/core/25-catch.js
new file mode 100644
index 000000000..54f028a4a
--- /dev/null
+++ b/nodes/core/core/25-catch.js
@@ -0,0 +1,29 @@
+/**
+ * Copyright 2015 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+
+module.exports = function(RED) {
+ "use strict";
+
+ function CatchNode(n) {
+ RED.nodes.createNode(this,n);
+ var node = this;
+ this.on("input",function(msg) {
+ this.send(msg);
+ });
+ }
+
+ RED.nodes.registerType("catch",CatchNode);
+}
diff --git a/red/nodes/Flow.js b/red/nodes/Flow.js
index e56f34afb..5f0ad559c 100644
--- a/red/nodes/Flow.js
+++ b/red/nodes/Flow.js
@@ -60,6 +60,7 @@ function createSubflow(sf,sfn,subflows) {
node_map[node.id] = node;
node._alias = node.id;
node.id = nid;
+ node.z = sfn.id;
newNodes.push(node);
}
// Update all subflow interior wiring to reflect new node IDs
@@ -80,6 +81,7 @@ function createSubflow(sf,sfn,subflows) {
var subflowInstance = {
id: sfn.id,
type: sfn.type,
+ z: sfn.z,
name: sfn.name,
wires: []
}
@@ -203,6 +205,46 @@ function diffNodeConfigs(oldNode,newNode) {
return false;
}
+function createCatchNodeMap(nodes) {
+ var catchNodes = {};
+ var subflowInstances = {};
+ /*
+ - a catchNode with same z as error node
+ - if error occurs on a subflow without catchNode, look at z of subflow instance
+ */
+ for (var id in nodes) {
+ if (nodes.hasOwnProperty(id)) {
+ if (nodes[id].type === "catch") {
+ catchNodes[nodes[id].z] = nodes[id];
+ }
+ }
+ }
+ for (var id in nodes) {
+ if (nodes.hasOwnProperty(id)) {
+ var m = /^subflow:(.+)$/.exec(nodes[id].type);
+ if (m) {
+ subflowInstances[id] = nodes[id];
+ }
+ }
+ }
+ for (var id in subflowInstances) {
+ if (subflowInstances.hasOwnProperty(id)) {
+ var z = id;
+ while(subflowInstances[z]) {
+ var sfi = subflowInstances[z];
+ if (!catchNodes[z]) {
+ z = sfi.z;
+ } else {
+ break;
+ }
+ }
+ if (catchNodes[z]) {
+ catchNodes[id] = catchNodes[z];
+ }
+ }
+ }
+ return catchNodes;
+}
var subflowInstanceRE = /^subflow:(.+)$/;
@@ -230,6 +272,8 @@ Flow.prototype.parseConfig = function(config) {
this.configNodes = {};
+ this.catchNodeMap = null;
+
var unknownTypes = {};
for (i=0;i