timeout tweak

This commit is contained in:
James Campos 2015-02-01 04:36:17 -08:00
parent 6705b3cdaf
commit a47b8077b2
1 changed files with 4 additions and 6 deletions

View File

@ -102,17 +102,15 @@ function Fetch(url, opts) {
// send request
var req = request(options);
var started = false;
req.on('socket', function(socket) {
if (!started && options.timeout) {
started = true;
if (options.timeout) {
req.once('socket', function(socket) {
setTimeout(function() {
req.abort();
reject(new Error('network timeout at: ' + uri.href));
}, options.timeout);
}
});
}
req.on('error', function(err) {
reject(new Error('request to ' + uri.href + ' failed, reason: ' + err.message));