Any ideas why the value returned from getBatchedContent
is null
, given the code sample below?
import rp from 'request-promise';
import _ from 'lodash';
function getBatchedContent(size, page) {
return Promise.resolve(fetchBatchedContent(size, page)); // Getting `null` here.
}
function fetchBatchedContent(size, page) {
var options = {
uri: `http://www.example.com/posts?type=vogue-fashion-shows&filter[posts_per_page]=${size}&page=${page}`
};
return rp(options)
.then(function (res) {
res = JSON.parse(res);
// res is an array of content objects.
return _.map(res, function (obj) { // logged value of `_.map()` is correct.
return transformContent(obj);
});
});
}
function transformContent(obj) {
return {
id: obj.ID,
title: obj.title,
// etc.
};
}
Perhaps add a .catch(function (error) {debugger;})
to fetchBatchedContent
. Does it return what you expect?
I'm not sure what you're inputting into Promise.resolve
that can directly result in null
? That seems very odd to me, even Promise.resolve(Promise.reject('foo'))
would return a Promise. (a rejected one).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.