I use the bluebird promises structure to execute a POST request and get a response to this POST request:
var Promise = require('bluebird'); var request = Promise.promisifyAll(require('request')); // Set the headers var headers = { 'User-Agent': 'Super Agent/0.0.1', 'Content-Type': 'application/x-www-form-urlencoded' } var options = []; var scores = []; // Configure the request options[0] = { url: 'https://api.havenondemand.com/1/api/sync/analyzesentiment/v1', method: 'POST', headers: headers, form: {'apikey': 'XXXXXXXXXXX', 'text': 'I love dogs'} } // Start the request request.postAsync(options[0]).spread(function(response, body) { if (response.statusCode == 200) { var answer = JSON.parse(body); scores[0] = answer['aggregate']['score']; } }).then(function() { console.log(scores[0]) });
This is the error message I get:
Unhandled rejection TypeError: expecting an array or an iterable object but got [object Null] at apiRejection (/Users/vphuvan/demos/node_modules/bluebird/js/release/promise.js:10:27) etc.
What do I need to do to resolve this error message?
Note: the version of bluebird that I am using now is 3.0.5
source share