node-http-digest-client icon indicating copy to clipboard operation
node-http-digest-client copied to clipboard

Can not handle request error

Open otaky opened this issue 9 years ago • 0 comments

Hi,

When request an invalid address, you may got an error like this:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: connect ETIMEDOUT
    at errnoException (net.js:901:11)
    at Object.afterConnect [as oncomplete] (net.js:892:19)

And I have no good way to handle it.

Maybe HTTPDigest.prototype.request could return its http.ClientRequest object. Like this:

 HTTPDigest.prototype.request = function (options, callback) {
    var self = this;
    var req = http.request(options, function (res) {
      self._handleResponse(options, res, callback);
    });
    req.end();
    return req;
  };

And to handle error like this:

var req = digest.request({
    ...
}, function (res) {
  ...
  res.on('error', function (err) {
    console.log('oh noes');
  });
});

req.on('error', function (err) {
  console.log('request error!');
});

otaky avatar Oct 14 '15 02:10 otaky