browserify / http-browserify

node's http module, but for the browser
MIT License
244 stars 110 forks source link

How to catch ECONNREFUSED? #51

Closed goloroden closed 1 year ago

goloroden commented 10 years ago

In Node.js, when using the request function of the http module, you can subscribe to the error events of the returned object, such as:

var http = require('http');

var req = http.request('aaa.bbb.ccc.ddd', function (res) {
  console.log(res.statusCode);
});

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

req.end();

When I run this with a non-existent IP on Node.js, everything is fine, and the result is ### printed to the console.

When I run this using http-browserify in Chrome, I get an uncaught exception. Am I doing something wrong?

JamesMessinger commented 9 years ago

I'm having the same issue. Any resolution to this?

goloroden commented 9 years ago

Unfortunately, I don't have one :-(

langri-sha commented 8 years ago

I believe you will have to listen to the window for these uncaught network errors and decide what to do with them.