3

I'm getting 400 code back from the server, so I need to check what's wrong with my request. How to print the request's raw text?

That's my code right now:

request.post('/api/events/')
.send(preparedEvent)
.end((err, res) => {
    if(!err){
        let returnedEvent = fromIsoToMoment(res.body);
        state = [...state, returnedEvent];
    }
    else {
        console.log(err);
    }
});
return state;

1 Answers1

3

Update: From the source: Superagent, in the send method, exposes the serialized data as this._data

 let req = request
   .post('/api/pet')
   .send({ name: 'Manny', species: 'cat' })

  req.end(function(err, res){
     if (res.ok) {
       console.log('yay got ' + JSON.stringify(res.body));
     } else {
       console.log('Oh no! error ', req._data); // Logs the data sent in request.
     }
   });
lorefnon
  • 12,875
  • 6
  • 61
  • 93