Sirhc
4 November 2024 10:47
1
Hello
I have a function that communicates to a devices IP address.
If the device isn't on the network, the debug window shows this:
function : (error)
request to IP_ADDR failed, reason: connect EHOSTUNREACH IP_ADDR
How do I pick this error up in the function itself or in a function after it so I can flag that the device isn't connected
Hard to say with such little info but at a guess try {} catch () {}
- 100% depends on async await or sync or promise based code.
Sirhc
4 November 2024 11:05
3
Steve-Mcl:
try {} catch () {}
Sorry, does this go in the function node itself?
again ......
where is the error generated? show us the flow / code
Sirhc
4 November 2024 22:13
5
Steve-Mcl:
try {} catch () {}
Thanks for the reply and patience.
I am utilising this package:
https://github.com/bbreukelen/node-rainbird/blob/master/index.js
In the function node I have:
var temp = new RainBirdClass(MY_IP, MY_PASS);
let temp1 = await temp.getActiveZones();
msg.payload = temp1;
However, if the controller is not on the network, I see the above mentioned error in debug, which looks like it's the error returned line 139 of index.js?
Line 139: reject(err.message)
;
Instead of the function giving me an error in debug, I want to know that the controller is not on the network.
Open the function node, select the set-up tab, set output count to 2. This way, good messages go out of the top node, errors go out the bottom output.
const temp = new RainBirdClass(MY_IP, MY_PASS);
try {
msg.payload = await temp.getActiveZones()
} catch (error) {
msg.payload = "something went wrong"
msg.error = error
return [null, msg] // send to 2nd output
}
return msg
Alternatively, add a catch node and point it at the function.