my openstates.billDetail function has a call back function inside of it, and I'm getting an error: 'callback must be a function', but my callback appears to be a function!
app.get('/search/:searchTerm', function(req, response) {
var nameArray = req.params.searchTerm.split('_');
var bills = []
var billIds = []
openstates.legSearch({
first_name: nameArray[0],
last_name: nameArray[1]
}, function(err, data) {
if (!err) {
openstates.billSearch({
state: 'CA',
chamber: 'lower',
page: '1'
}, function(err, data) {
for (var billIndex = 0; billIndex < data.length; billIndex++) {
billIds.push(data[billIndex].id)
}
for (var billIdIndex = 0; billIdIndex < billIds.length; billIdIndex++) {
openstates.billDetail(billIds[billIdIndex], function(err, data) {
console.log(data);
})
}
})
}
})
})
Anyone have any thoughts on this? my other callbacks work fine...
I tested your code, and it works perfectly fine.
I added the following to test it:
var openstates = {legSearch: function(a, cb){ cb(null, 'aa'); },
billSearch: function(a, cb){ cb(null, 'bb'); },
billDetail: function(a, cb){ cb(null, 'cc'); }};
Got no error, and the last function print 'cc' as expected.
BTW, you do not send any response back, I am not sure if this is on purpose.