From 95cfb0238488aa993d1ee49f3c58f1f1c8f9133a Mon Sep 17 00:00:00 2001 From: Tom Zellman Date: Wed, 21 Jul 2021 15:33:59 -0400 Subject: [PATCH] fix: chunk the full body response before calling back with an error in essence, wait for the response to end before calling back to the caller --- lib/client.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/client.js b/lib/client.js index b875461..89e60db 100644 --- a/lib/client.js +++ b/lib/client.js @@ -115,21 +115,22 @@ Client.prototype.methodCall = function methodCall(method, params, callback) { return err } - if (response.statusCode == 404) { - callback(__enrichError(new Error('Not Found'))) - } - else { - this.headersProcessors.parseResponse(response.headers) - - var deserializer = new Deserializer(options.responseEncoding) - - deserializer.deserializeMethodResponse(response, function(err, result) { - if (err) { - err = __enrichError(err) - } - callback(err, result) - }) - } + response.on('end', () => { + if (response.statusCode == 404) { + callback(__enrichError(new Error('Not Found'))) + } else { + this.headersProcessors.parseResponse(response.headers) + + var deserializer = new Deserializer(options.responseEncoding) + + deserializer.deserializeMethodResponse(response, function (err, result) { + if (err) { + err = __enrichError(err) + } + callback(err, result) + }) + } + }); }.bind(this)) request.on('error', callback)