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?
In Node.js, when using the
request
function of thehttp
module, you can subscribe to theerror
events of the returned object, such as: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?