Permalink
Browse files

raise twitter errors

  • Loading branch information...
1 parent efd0c7c commit ea69ece03c9e851344ef4fbfb6d68a3b03777093 @technoweenie technoweenie committed Jul 25, 2012
Showing with 20 additions and 2 deletions.
  1. +20 −2 services/twitter.rb
View
@@ -32,8 +32,26 @@ def post(status)
params = { 'status' => status, 'source' => 'github' }
access_token = ::OAuth::AccessToken.new(consumer, data['token'], data['secret'])
- consumer.request(:post, "/1/statuses/update.json",
- access_token, { :scheme => :query_string }, params)
+ res = consumer.request(:post, "/1/statuses/update.json",
+ access_token, { :scheme => :query_string }, params)
+ if res.code !~ /^2\d\d/
+ raise_response_error(res)
+ end
+ end
+
+ def raise_response_error(res)
+ error = "Received HTTP #{res.code}"
+ if msg = response_error_message(res)
+ error << ": "
+ error << msg
+ end
+
+ raise_config_error(error)
+ end
+
+ def response_error_message(res)
+ JSON.parse(res.body)
+ rescue
end
def consumer_key

0 comments on commit ea69ece

Please sign in to comment.