From 903a1230497ba65dad9e13bbb8261d39d1eba9fd Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 16 Aug 2018 14:45:54 +0100 Subject: [PATCH] Reset twitter polling on any api errors --- social/twitter/27-twitter.js | 14 +++++++++++++- social/twitter/package.json | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/social/twitter/27-twitter.js b/social/twitter/27-twitter.js index 16418a53..4987f71d 100644 --- a/social/twitter/27-twitter.js +++ b/social/twitter/27-twitter.js @@ -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); diff --git a/social/twitter/package.json b/social/twitter/package.json index 99feedfe..a86d7bdf 100644 --- a/social/twitter/package.json +++ b/social/twitter/package.json @@ -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",