dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

Getting error if wiki page is not containing any images?? #5

Closed riteshbabu closed 10 years ago

riteshbabu commented 10 years ago

userdata = ['accenture','Accenture top 50 business intellectuals', 'Accenture Tower'];

async.each(userdata, function(item, cb){ var peoples = [ ]; wiki.page(item, function(err, page){ page.images(function(err, data){ peoples.push({name:item,images:data}); cb(); });

  });
}, function(err, data){
   if (err) {
    return callback(err);
  }       
   return callback(null,peoples);
});

See here i am getting error "Cannot read property 'pages' of undefined" because "Accenture top 50 business intellectuals" wiki page doesn't contain any images so its giving error if wiki page contain single image also then its working fine. I tried to console err of page.images function also but its not giving any output and same error coming.

Please can you give me solutions of this error or if wiki page doesn't have any images then how can i solve this issues???

Thank you for your previous issues answer.Now its working fine.

dijs commented 10 years ago

There was definitely a bug, but as far as what you are trying to do, use something like this...

items = ['accenture', 'Accenture top 50 business intellectuals', 'Accenture Tower'];

eachItem = function(item, cb) {
  return wiki.page(item, function(err, page) {
    if (err) {
      return cb(err);
    } else {
      return page.images(function(err, data) {
        return cb(err, {
          name: item,
          images: data
        });
      });
    }
  });
};

async.map(items, eachItem, function(err, pageImages) {
  if (err) {
    return console.log(err);
  } else {
    return console.log(pageImages);
  }
});