Permalink
Browse files

Added more data to some of the exceptions to help with debugging.

  • Loading branch information...
1 parent 6d7706c commit 72d46c4804a30b28ab351a5a0d37d6bc664e577e @jnunemaker jnunemaker committed Apr 5, 2009
Showing with 38 additions and 15 deletions.
  1. +1 −0 .gitignore
  2. +5 −1 History
  3. +3 −5 examples/connect.rb
  4. +8 −0 examples/helpers/config_store.rb
  5. +16 −6 lib/twitter.rb
  6. +5 −3 lib/twitter/request.rb
View
@@ -3,3 +3,4 @@ pkg
log
doc
twitter-*.gem
+rdoc
View
@@ -1,4 +1,8 @@
-0.5.0 - March 3, 2009
+0.5.1 - April 5, 2009
+* 1 minor change
+ * Added data error hash returned from twitter to a few of the exceptions to help with debugging
+
+0.5.0 - April 3, 2009
* 1 major rewrite for OAuth
* Backwards compatibility thrown to the wind
* Proxy no longer supported (someone please add it back in, I never use proxies)
View
@@ -7,20 +7,18 @@
if config['atoken'] && config['asecret']
oauth.authorize_from_access(config['atoken'], config['asecret'])
- # puts oauth.access_token.get("/statuses/friends_timeline.json")
twitter = Twitter::Base.new(oauth)
pp twitter.friends_timeline
elsif config['rtoken'] && config['rsecret']
oauth.authorize_from_request(config['rtoken'], config['rsecret'])
- puts oauth.access_token.get("/statuses/friends_timeline.json")
+ twitter = Twitter::Base.new(oauth)
+ pp twitter.friends_timeline
config.update({
'atoken' => oauth.access_token.token,
'asecret' => oauth.access_token.secret,
- 'rtoken' => nil,
- 'rsecret' => nil,
- })
+ }).delete('rtoken', 'rsecret')
else
config.update({
'rtoken' => oauth.request_token.token,
@@ -19,12 +19,20 @@ def []=(key, value)
@config[key] = value
end
+ def delete(*keys)
+ keys.each { |key| @config.delete(key) }
+ save
+ self
+ end
+
def update(c={})
@config.merge!(c)
save
+ self
end
def save
File.open(file, 'w') { |f| f.write(YAML.dump(@config)) }
+ self
end
end
View
@@ -7,12 +7,22 @@
end
module Twitter
- class RateLimitExceeded < StandardError; end
- class Unauthorized < StandardError; end
- class Unavailable < StandardError; end
- class InformTwitter < StandardError; end
- class NotFound < StandardError; end
- class General < StandardError; end
+ class TwitterError < StandardError
+ attr_reader :data
+
+ def initialize(data)
+ @data = data
+ super
+ end
+ end
+
+ class RateLimitExceeded < TwitterError; end
+ class Unauthorized < TwitterError; end
+ class General < TwitterError; end
+
+ class Unavailable < StandardError; end
+ class InformTwitter < StandardError; end
+ class NotFound < StandardError; end
def self.firehose
View
@@ -51,11 +51,13 @@ def make_friendly(response)
def raise_errors(response)
case response.code.to_i
when 400
- raise RateLimitExceeded, "(#{response.code}): #{response.message}"
+ raise RateLimitExceeded.new(parse(response)), "(#{response.code}): #{response.message} - #{data['error']}"
when 401
- raise Unauthorized, "(#{response.code}): #{response.message}"
+ data = parse(response)
+ raise Unauthorized.new(data), "(#{response.code}): #{response.message} - #{data['error']}"
when 403
- raise General, "(#{response.code}): #{response.message}"
+ data = parse(response)
+ raise General.new(data), "(#{response.code}): #{response.message} - #{data['error']}"
when 404
raise NotFound, "(#{response.code}): #{response.message}"
when 500

0 comments on commit 72d46c4

Please sign in to comment.