From e56f91373a2d794b61c9ec6084a0fac391235e47 Mon Sep 17 00:00:00 2001 From: Kirill Solovev Date: Fri, 8 May 2015 12:47:00 +0300 Subject: [PATCH] Access to body of non-200 responses in stream mode --- index.js | 4 ++-- test/test-http.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index f7bd1a7..aabdd74 100644 --- a/index.js +++ b/index.js @@ -65,8 +65,8 @@ function got(url, opts, cb) { if (!cb) { proxy = duplexify(); // forward errors on the stream - cb = function (err) { - proxy.emit('error', err); + cb = function (err, data, response) { + proxy.emit('error', err, data, response); }; } diff --git a/test/test-http.js b/test/test-http.js index 99ebb9d..1dec893 100644 --- a/test/test-http.js +++ b/test/test-http.js @@ -89,8 +89,10 @@ tape('emit response object to stream', function (t) { tape('proxy errors to the stream', function (t) { got(s.url + '/404') - .on('error', function (err) { + .on('error', function (err, data, res) { t.equal(err.code, 404); + t.equal(data, 'not'); + t.ok(res); t.end(); }); });