Flow:
Code: Select all
[{"id":"566d13822a85d69d","type":"tab","label":"common","disabled":false,"info":"","env":[]},{"id":"inject","type":"inject","z":"566d13822a85d69d","name":"Inject","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":390,"y":100,"wires":[["function"]]},{"id":"function","type":"function","z":"566d13822a85d69d","name":"Generate Error","func":"\nif (Math.random() < 0.5) {\n node.status({ fill: \"red\", shape: \"ring\", text: \"< 0.5\" });\n throw new Error(\"This is an error message\");\n} else {\n node.status({fill:\"green\",shape:\"ring\",text:\">= 0.5\"});\n msg.payload = \">= 0.5\";\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":100,"wires":[[]]},{"id":"complete","type":"complete","z":"566d13822a85d69d","name":"Success","scope":["function"],"x":540,"y":160,"wires":[["debug-success"]]},{"id":"catch","type":"catch","z":"566d13822a85d69d","name":"Error","scope":["function","complete"],"uncaught":false,"x":530,"y":200,"wires":[["debug-error"]]},{"id":"debug-success","type":"debug","z":"566d13822a85d69d","name":"Debug Success","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":160,"wires":[]},{"id":"debug-error","type":"debug","z":"566d13822a85d69d","name":"Debug Error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"error","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":200,"wires":[]},{"id":"da166f85e8a2ed46","type":"status","z":"566d13822a85d69d","name":"","scope":["function"],"x":540,"y":240,"wires":[["2041fa1fe879b3c6"]]},{"id":"2041fa1fe879b3c6","type":"debug","z":"566d13822a85d69d","name":"Debug Error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"status","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":240,"wires":[]}]