Fix dns uncaught exception
Closed this issue · 3 comments
chutiphon-k commented
Fix case receive uncaught exception error when cannot call dns server which is the cause of node server down.
ex:
Error: getaddrinfo ENOTFOUND api.omise.co api.omise.co:443
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
fix by handle event error
in function _responseHandler
Lines 13 to 36 in bce1acb
function _responseHandler(req) {
return new Promise(function(resolve, reject) {
req
.on('response', function(res) {
var resp = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
resp += chunk;
});
res.on('end', function() {
try {
logger.log('info', resp);
resp = JSON.parse(resp);
if (resp.object === 'error') {
reject(resp);
} else {
resolve(resp);
}
} catch (err) {
reject(err);
}
});
})
.on('error', function(err) { // add this line
reject(err);
});
});
}
varshard commented
Thank you.
varshard commented
@chutiphon-k I'ved open a PR for this issue.
varshard commented
The 0.5.6 release should fix this.