[common] The complete, catch and status nodes example

Questions and Answers

Moderator: IoTStudio Support

Post Reply
IoTStudio Support
Posts: 39
Joined: Wed Nov 23, 2022 9:26 am

[common] The complete, catch and status nodes example

Post by IoTStudio Support »

This flow is for complete, catch and status nodes example. Use a Inject node to trigger a function node. The function node use Math.random to gen value, if value < 0.5 will throw a Error exceptioin and status set red else is normal return msg and status is green. If function node throw a exception, the catch node will catch and report. If function normal return then complete node will report it. The status node will report function status info.
common - complete, catch and status nodes
common - complete, catch and status nodes
common nodes.PNG (31.31 KiB) Viewed 3752 times
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":[]}]
Best Regards,
IoT Studio Support Team
Post Reply