Added error handling when API calls timeout

This commit is contained in:
Anna 2010-05-04 14:32:43 -04:00
parent 6044fa27d2
commit f37246f30b
3 changed files with 66 additions and 32 deletions

View file

@ -4,7 +4,7 @@
import sys, ConfigParser, os, re, optparse, shelve
import gtk, gtk.glade, gobject
from urllib2 import HTTPError
from urllib2 import HTTPError,URLError
from twitterwidgets import TweetPane
import apithreads
@ -189,7 +189,13 @@ class MyTwitter():
text = self.update_entry.get_text()
self.update_entry.set_text("")
with self.api.lock:
self.api.PostUpdate(text, in_reply_to_status_id=self.reply_id)
try:
self.api.PostUpdate(text, in_reply_to_status_id=self.reply_id)
except HTTPError,URLError:
self.update_status_bar('Failed to post tweet')
self.reply_id = None
return
self.reply_id = None
self.update_status_bar('Tweet Posted')
@ -226,7 +232,10 @@ class MyTwitter():
def on_retweet(self, widget, data):
with self.api.lock:
self.api.PostRetweet(data['id'])
try:
self.api.PostRetweet(data['id'])
except HTTPError,URLError:
self.update_status_bar('Failed to retweet')
def on_reply_to(self, widget, data):
@ -360,16 +369,24 @@ class MyTwitter():
user_name = re.sub('^user: ', '', current_pane.get_list_name())
if current_pane.get_following():
with self.api.lock:
self.api.DestroyFriendship(user_name)
try:
self.api.DestroyFriendship(user_name)
except HTTPError,URLError:
self.update_status_bar('Failed to unfollow user.')
return
current_pane.set_following(False)
else:
with self.api.lock:
self.api.CreateFriendship(user_name)
try:
self.api.CreateFriendship(user_name)
except HTTPError,URLError:
self.update_status_bar('Failed to follow user.')
return
current_pane.set_following(True)
self.update_follow_button(current_pane)
# pane should be the currently active pane
def update_follow_button(self, pane):
if not pane.get_is_user():