Catch exceptions from posting to Twitter

This change updates Statusbot to catch exceptions from posting to
Twitter. This fixes an issue where Statusbot crashes if Twitter returns
a non-OK status from a post. An example can be found here [1].

http://paste.openstack.org/show/602748/

Change-Id: Iae3ad57e2e205b60a730ddffe8cba0f68d1f99bb
This commit is contained in:
Ben Kero 2017-03-14 14:38:33 -07:00
parent 57d6ed9ad7
commit aa3e3616d8
1 changed files with 9 additions and 3 deletions

View File

@ -173,11 +173,17 @@ class Tweet(UpdateInterface):
tweets = textwrap.wrap(msg, 120)
if len(tweets) == 1:
# Don't prefix statuses that fit
self.api.PostUpdate(tweets[0])
try:
self.api.PostUpdate(tweets[0])
except twitter.TwitterError:
self.log("Error encountered posting to Twitter")
else:
for index in range(0, len(tweets)):
self.api.PostUpdate("{index}/{tweet}".format(
index=index, tweet=tweets[index]))
try:
self.api.PostUpdate("{index}/{tweet}".format(
index=index, tweet=tweets[index]))
except twitter.TwitterError:
self.log("Error encountered posting to Twitter")
def alert(self, msg=None):
self.update(msg)