From 759218c0212245bb25dbdb9cd8a6083f0f0904d9 Mon Sep 17 00:00:00 2001 From: Reason Date: Mon, 19 May 2014 11:43:36 -0500 Subject: [PATCH] Add an error listener to prevent socket hang up and similar errors leading to thrown exceptions. --- lib/http_client.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/http_client.js b/lib/http_client.js index c2eb04d..1578fc7 100644 --- a/lib/http_client.js +++ b/lib/http_client.js @@ -128,6 +128,14 @@ client.prototype.request = function(method, path, params, callback){ }); }); + // This should only occur for errors such as a socket hang up prior to any + // data being received, or SSL-related issues. + req.on('error', function(err) { + if(typeof callback == 'function'){ + callback(err, null, 0); + } + }); + if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){ req.write(body); }