Skip to content

Commit

Permalink
Use .read() to get response body instead of accessing internal buff…
Browse files Browse the repository at this point in the history
…er directly
  • Loading branch information
sgress454 committed Jul 8, 2016
1 parent d42d598 commit a5ab134
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/app/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ module.exports = function request( /* address, body, cb */ ) {

// Only dump the buffer if a callback was supplied
if (cb) {
clientRes.body = Buffer.concat(clientRes._readableState.buffer).toString();

// Attempt to read the response buffer into a string
try {
clientRes.body = JSON.parse(clientRes.body);
clientRes.body = clientRes.read();
if (clientRes.body !== null) {
clientRes.body = clientRes.body.toString();
clientRes.body = JSON.parse(clientRes.body);
}
} catch (e) {}

// Don't include body if it is empty
if (!clientRes.body) delete clientRes.body;
if (!clientRes.body) {delete clientRes.body;}

// If status code is indicative of an error, send the
// response body or status code as the first error argument.
Expand Down

0 comments on commit a5ab134

Please sign in to comment.