10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/twitter_dispatch/proxy/shared.rb', line 10
def handle_response(response)
case response
when Net::HTTPOK
begin
JSON.parse(response.body)
rescue JSON::ParserError
response.body
end
when Net::HTTPUnauthorized
raise TwitterDispatch::Unauthorized, 'API Authorization failed. Check user credentials and OAuth consumer permission levels.'
else
message = begin
JSON.parse(response.body)['error']
rescue JSON::ParserError
if match = response.body.match(/<error>(.*)<\/error>/)
match[1]
else
"An unknown #{response.code} error occurred processing your API request."
end
end
raise TwitterDispatch::HTTPError, message
end
end
|