1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Reset twitter polling on any api errors

This commit is contained in:
Nick O'Leary 2018-08-16 14:45:54 +01:00
parent 85ddffb98f
commit 903a123049
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 14 additions and 2 deletions

View File

@ -374,6 +374,10 @@ module.exports = function(RED) {
var res = result.body;
if (res.errors) {
node.error(res.errors[0].message);
clearInterval(pollId);
node.timeout_ids.push(setTimeout(function() {
node.poll(interval,url,opts);
},interval))
return;
}
if (res.length > 0) {
@ -438,7 +442,11 @@ module.exports = function(RED) {
node.debug("Twitter DM Poll, rateLimitRemaining="+result.rateLimitRemaining+" rateLimitTimeout="+Math.floor(result.rateLimitTimeout/1000)+"s");
var res = result.body;
if (res.errors) {
throw new Error(res.errors[0].message);
node.error(res.errors[0].message);
node.timeout_ids.push(setTimeout(function() {
node.pollDirectMessages();
},interval))
return;
}
var since = "0";
var messages = res.events.filter(tweet => tweet.type === 'message_create' && tweet.id > since);
@ -459,6 +467,10 @@ module.exports = function(RED) {
var res = result.body;
if (res.errors) {
node.error(res.errors[0].message);
clearInterval(pollId);
node.timeout_ids.push(setTimeout(function() {
node.pollDirectMessages();
},interval))
return;
}
var messages = res.events.filter(tweet => tweet.type === 'message_create' && tweet.id > since);

View File

@ -1,6 +1,6 @@
{
"name": "node-red-node-twitter",
"version": "1.1.0",
"version": "1.1.1",
"description": "A Node-RED node to talk to Twitter",
"dependencies": {
"twitter-ng": "0.6.2",