Skip to content

Commit

Permalink
worked on #61 - Polling Error maybe fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
CptPie committed Oct 19, 2017
1 parent 2d23824 commit 5081c8f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ bot.getMe()
process.exit();
});

/* This might work or it won't, unable to test it at the moment.
* This function triggers on a polling error and sends a message to the console and therefore to the logfile.
* Afterwards it stops polling for 10 seconds and starts polling again (i don't know if it fixes the problem but it surly reduces the console spam.)
*/

bot.on('polling_error', (error) => {
var date = new Date()
console.log(date.getDate()+"-"+(date.getMonth()+1)+"-"+date.getFullYear()+"/"+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+" Error: "+error.code+ " Telegram's Famous 502 Error."); // => 'EFATAL'
bot.stopPolling().then(sleep(10000, bot.startPolling()));
});


function sleep(time, callback) {
var stop = new Date().getTime();
while(new Date().getTime() < stop + time) {
;
}
callback();
}


/**
Expand Down

0 comments on commit 5081c8f

Please sign in to comment.