Skip to content

Instantly share code, notes, and snippets.

@davidfrey
Created April 5, 2012 22:45
Show Gist options
  • Save davidfrey/2314767 to your computer and use it in GitHub Desktop.
Save davidfrey/2314767 to your computer and use it in GitHub Desktop.
Twitter::Error::ServiceUnavailable
attempt_count = 0
begin
response = Twitter.user_timeline('davidfrey', {:count=>200, :include_rts => true, :include_entitites => true})
rescue Twitter::Error => error
attempts_count += 1
code = error.class.to_s.gsub('Twitter::Error::','')
case code.downcase
when /notfound|unauthorized/
#void collection
when /clienterror|notacceptable|badrequest|badgateway/
#skip and come back later
when /servererror|serviceunavailable/
#skip and come back later
end
rescue StandardError => error
# attempt to rescue anything not caught above
end
Twitter::Error::ServiceUnavailable: (__-){ Twitter is over capacity.
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/twitter-2.1.0/lib/twitter/response/raise_server_error.rb:17:in `on_complete'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/response.rb:9:in `block in call'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/response.rb:62:in `on_complete'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/request/url_encoded.rb:14:in `call'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/request/multipart.rb:13:in `call'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/twitter-2.1.0/lib/twitter/request/oauth.rb:17:in `call'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/twitter-2.1.0/lib/twitter/request/multipart_with_file.rb:17:in `call'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/connection.rb:210:in `run_request'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/faraday-0.7.6/lib/faraday/connection.rb:93:in `get'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/twitter-2.1.0/lib/twitter/request.rb:23:in `request'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/twitter-2.1.0/lib/twitter/request.rb:11:in `get'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/twitter-2.1.0/lib/twitter/client/accounts.rb:22:in `rate_limit_status'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/twitter-2.1.0/lib/twitter.rb:17:in `method_missing'
from /Users/freyd/Dropbox/Projects/DesignLab/number-five/lib/designlab/collector/twitter.rb:64:in `remaining_hits'
from /Users/freyd/Dropbox/Projects/DesignLab/number-five/lib/designlab/collector/twitter.rb:70:in `fetch'
from /Users/freyd/Dropbox/Projects/DesignLab/number-five/lib/designlab/collector/twitter.rb:30:in `user'
from /Users/freyd/Dropbox/Projects/DesignLab/number-five/lib/designlab/client.rb:35:in `block (2 levels) in collect'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.2.2/lib/active_record/associations/collection_proxy.rb:89:in `each'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.2.2/lib/active_record/associations/collection_proxy.rb:89:in `method_missing'
from /Users/freyd/Dropbox/Projects/DesignLab/number-five/lib/designlab/client.rb:27:in `block in collect'
from /Users/freyd/Dropbox/Projects/DesignLab/number-five/lib/designlab/client.rb:19:in `each'
from /Users/freyd/Dropbox/Projects/DesignLab/number-five/lib/designlab/client.rb:19:in `collect'
from /Users/freyd/Dropbox/Projects/DesignLab/number-five/lib/designlab.rb:19:in `method_missing'
from (irb):2
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
from /Users/freyd/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment