Closed taras-d closed 6 years ago
After exploring data.results
array I noticed that every result item will have err
property if error occurred.
To determine if error occured I need to check if there is at least one item with error:
const isError = data.results.some(item => item.err);
Hmm yeah it seems that the only places where errors are put is in data.results
. It's not obvious that you want to aggregate them in err
, because the fact that one of 10 attempts failed, doesn't mean that you consider this ping as failed (you should still get a reasonable estimate).
You're right. One failed attempt doesn't mean that ping failed. I think is better to check if all attempts failed - data.results.every(item => item.err).
It's not even clear to me that failure of all attempts means that the whole ping was unsuccessful. Maybe you just expected the host to be down? There was no issue with setting up the connections, they were just rejected.
I just want to check if site available by sending ping to ip address.
I was confused by err
which always undefined
.
Now I understand that this is just convention/standard to use "error-first" callbacks in node world).
Thanks for your responses!
Ping
err
argument always undefined regardless address valid or not.Example: