question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

response body(res.body) is always undefined.

See original GitHub issue
version: 1.8.3 
platform: nodejs

I am trying to use super agent in my nodejs application and find an issue that ‘res.body’ in my response is always undefined. The content in response is in Json and I can see it in res.text. After some investigation I am able to spot the code which cases this issue:

// /lib/node/index
// line 883 to 886

parse(res, function(err, obj){ // Expects an argument
  if (err && !self._aborted) self.callback(err);
  res.body = obj;
}

// lib/node/parsers/text.js
module.exports = function(res, fn){
  res.text = '';
  res.setEncoding('utf8');
  res.on('data', function(chunk){ res.text += chunk; });
  res.on('end', fn); // No argument is given.
};

As the above indicates, parse function’s callback expects one argument but nothing is given when it is called.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kornelskicommented, Jun 9, 2016

The text parser sets only .text.

For custom parsers it’s sort-of broken. The end callback doesn’t wait for the parser to finish - #950, so you need .buffer(true).

0reactions
jeremy-linchaocommented, Oct 24, 2016

thanks, @pornel

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express.js req.body undefined - Stack Overflow
I read that this problem is caused by the lack of app.use(express.bodyParser()); but as you can see I call it before the routes....
Read more >
response body(res.body) is always undefined. #990 - GitHub
I am trying to use super agent in my nodejs application and find an issue that 'res.body' in my response is always undefined....
Read more >
How to fix "req.body undefined" in Express.js
In this post we will learn how to fix the "req.body undefined" error in Express.js Framework.
Read more >
req.body undefined in POST request - Google Groups
I seem to have a problem with req.body being "undefined" when using a. POST request. Im using expresso to do the POST: --...
Read more >
5.x API - Express.js
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body ), or an empty...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found