I'm using Node.js 7.8.0 and I'm trying to send HTTP-request to some host, sometimes the desired host doesn't exist. In such case, I get the following message:
events.js:163
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND js.js js.js:80
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:73:26)
Press any key to continue...
where js.js is the demo of non existent host. It's important to note, that everything works correctly, if I send the same request to the existing host.
The problem is that this error leads to crash of my Node.js application, while I need to keep the app running.
I already checked, my HTTP-request doesn't contain http/https/port in the field of host.
I tried to use try/catch, domains, and res.on('error', exitHandlerCB) approaches, nothing works. The only way that worked for me is process.on('uncaughtException', exitHandlerCB);, but this one leads to the stop of my Node.js app.
Is there any way to catch the error due to request to non existing host and to continue the application flow?
via Mike B.
No comments:
Post a Comment