Can not catch Error: connect ECONNREFUSED



I am develobing node js tool to get data from octoprint API

And I want to cover if my tool running but octoprint not running
When I try to run my tool when octoprint turned off
I face this error

      throw er; // Unhandled 'error' event

Error: connect ECONNREFUSED
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)

I try to catch it but I fail

Can someone help me with this
How I can catch it so I can run octoprint then try to connect

Thank you


I suggest you ask that in a NodeJS forum, it's a bit off topic here.


Take a look at my octo-client Node module. I doubt that I covered every possibility but it's certainly NodeJS-based.


I really like your octo-client and I am working on it
also I add some functionality to it so it can help in my tool

Thank you

About my issue

I solve it by adding this to my code

// handle