From 1b3aca9ab7cc27f00ca80ab67c917678cd29b56b Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 11 May 2014 00:31:31 +0200 Subject: [PATCH] better error handling --- index.js | 6 ++++-- test.js | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7221fe2..b5975cd 100644 --- a/index.js +++ b/index.js @@ -49,10 +49,12 @@ module.exports = function (url, opts, cb) { ret += data; }); - res.on('end', function () { + res.once('error', cb); + + res.once('end', function () { cb(null, ret); }); - }).on('error', cb); + }).once('error', cb); }; get(url, opts, cb); diff --git a/test.js b/test.js index 9b44eb8..22b8eb5 100644 --- a/test.js +++ b/test.js @@ -42,4 +42,3 @@ it('should support optional options', function (done) { done(); }); }); -