Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not handle request error #12

Open
otaky opened this issue Oct 14, 2015 · 0 comments
Open

Can not handle request error #12

otaky opened this issue Oct 14, 2015 · 0 comments

Comments

@otaky
Copy link

otaky commented Oct 14, 2015

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!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant