Improved error handling.
This commit is contained in:
parent
4e7387fdda
commit
ab2cc762ee
1 changed files with 18 additions and 6 deletions
|
@ -3,15 +3,19 @@ require 'twitter'
|
||||||
class Channel::Twitter2
|
class Channel::Twitter2
|
||||||
include UserInfo
|
include UserInfo
|
||||||
|
|
||||||
def fetch (channel)
|
def connect(channel)
|
||||||
|
|
||||||
puts "fetching tweets (oauth_token#{channel[:options][:oauth_token]})"
|
|
||||||
@client = Twitter::Client.new(
|
@client = Twitter::Client.new(
|
||||||
:consumer_key => channel[:options][:consumer_key],
|
:consumer_key => channel[:options][:consumer_key],
|
||||||
:consumer_secret => channel[:options][:consumer_secret],
|
:consumer_secret => channel[:options][:consumer_secret],
|
||||||
:oauth_token => channel[:options][:oauth_token],
|
:oauth_token => channel[:options][:oauth_token],
|
||||||
:oauth_token_secret => channel[:options][:oauth_token_secret]
|
: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
|
# search results
|
||||||
if channel[:options][:search]
|
if channel[:options][:search]
|
||||||
|
@ -78,7 +82,15 @@ class Channel::Twitter2
|
||||||
|
|
||||||
# search (no user data is included, do extra lookup)
|
# search (no user data is included, do extra lookup)
|
||||||
elsif tweet['from_user_id']
|
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
|
end
|
||||||
|
|
||||||
# check if parent exists
|
# check if parent exists
|
||||||
|
|
Loading…
Reference in a new issue