Improved error handling.

This commit is contained in:
Martin Edenhofer 2012-05-29 22:06:10 +02:00
parent 4e7387fdda
commit ab2cc762ee

View file

@ -3,15 +3,19 @@ require 'twitter'
class Channel::Twitter2
include UserInfo
def fetch (channel)
puts "fetching tweets (oauth_token#{channel[:options][:oauth_token]})"
def connect(channel)
@client = Twitter::Client.new(
:consumer_key => channel[:options][:consumer_key],
:consumer_secret => channel[:options][:consumer_secret],
:oauth_token => channel[:options][:oauth_token],
:oauth_token_secret => channel[:options][:oauth_token_secret]
)
end
def fetch (channel)
puts "fetching tweets (oauth_token#{channel[:options][:oauth_token]})"
@client = connect(channel)
# search results
if channel[:options][:search]
@ -78,7 +82,15 @@ class Channel::Twitter2
# search (no user data is included, do extra lookup)
elsif tweet['from_user_id']
sender = @client.user(tweet.from_user_id)
begin
# reconnect for #<Twitter::Error::NotFound: Sorry, that page does not exist> workaround
@client = connect(channel)
sender = @client.user(tweet.from_user_id)
rescue Exception => e
puts "Exception: twitter: " + e.inspect
return
end
end
# check if parent exists