Skip to content

Instantly share code, notes, and snippets.

@greghesp
Created January 4, 2022 11:11
Show Gist options
  • Save greghesp/7f9076dc8b57c943880eedd87c7ed375 to your computer and use it in GitHub Desktop.
Save greghesp/7f9076dc8b57c943880eedd87c7ed375 to your computer and use it in GitHub Desktop.
Node Red Error Handling Flow
[{"id":"9c2bbc33.ea38a8","type":"tab","label":"Error Handling","disabled":false,"info":""},{"id":"c5d148b4.60be08","type":"component_in","z":"9c2bbc33.ea38a8","name":"Error Handling","api":[{"name":"error","type":"any","required":false},{"name":"title","type":"string","required":false}],"x":130,"y":80,"wires":[["48d15bee.5c8144"]]},{"id":"fd5aeffe.53525","type":"file","z":"9c2bbc33.ea38a8","name":"Exception Log","filename":"/share/logs/node-red-exceptions.log","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":540,"y":60,"wires":[[]]},{"id":"751e1c04.0448a4","type":"debug","z":"9c2bbc33.ea38a8","name":"Errors","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":120,"wires":[]},{"id":"48d15bee.5c8144","type":"function","z":"9c2bbc33.ea38a8","name":"Format","func":"let error = msg.error;\nlet title = msg.title;\nlet device = msg.topic;\n\nif(msg.topic == \"/config/home-assistant.log\") {\n if(/ERROR|WARNING/.test(msg.payload)) {\n msg.topic = 'HA Logging Alert';\n return msg;\n }\n}\n\nelse {\n msg = {\n payload: `Error #${error.source.count}: ${error.message} --> ${error.source.name} --> ${error.source.type} | ${error.source.id} | ${title} flow`,\n topic: `Error in ${title} flow`\n }\n \n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":80,"wires":[["fd5aeffe.53525","751e1c04.0448a4"]]},{"id":"e78ade49.a261e","type":"function","z":"9c2bbc33.ea38a8","name":"Format","func":"let error = msg.error;\nlet title = msg.title;\nlet device = msg.topic;\n\nif(msg.topic == \"/config/home-assistant.log\") {\n if(/ERROR|WARNING/.test(msg.payload)) {\n msg.topic = 'HA Logging Alert';\n return msg;\n }\n}\n\nelse {\n msg = {\n payload: `Error #${error.source.count}: ${error.message} --> ${error.source.name} --> ${error.source.type} | ${error.source.id} | ${title} flow`,\n topic: `Error in ${title} flow`\n }\n \n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":200,"wires":[["f50be203.3943a"]]},{"id":"f50be203.3943a","type":"file","z":"9c2bbc33.ea38a8","name":"Exception Log","filename":"/share/logs/home-assistant-exceptions.log","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":540,"y":200,"wires":[[]]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment