javascript - How to stop iteration on error | Node.js and MongoDB -


got little problem here that's taking me long solve. might idiot because feel simple problem cant wrap head around it. here's code:

 get_online = function (err, result) {         if (err) {             return next(err);         }         streamers_size = result.length;         result.map(             function (entry) {                 curl.get                     .to('https://api.twitch.tv/kraken/streams/' + entry.uname)                     .then(update_streamers);             }         );     },      update_streamers = function (err, result) {         var clean;         if (err) {             return next(err);         }         if (result.stream) {             db.collection('streamers').update({                 _id: result.stream.channel._id             }, {                 $set: {                     stream_preview: result.stream.preview.large,                     viewers: result.stream.viewers                 }             }, send_response);         }         else {             clean = result._links.channel.substring(result._links.channel.length, 38);             db.collection('streamers').update({                 uname: clean             }, {                 $set: {                     stream_preview: 'offline',                     viewers: 0                 }             }, send_response);         }     }, 

what's happening everytime failed request api fires update_streamers callback , triggers if(err), it's going send headers back: return next(err), if failed requests consecutive? therefore it'll send headers repetitively until error says can't send headers set blah blah. more of logical question more anything. question is, how stop iteration (as mentioned in title). appreciated.

create variable errorcount , initialize 0. whenever error, increase it. if 5, stop trying. if there success, set errorcount 0.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -