better handling of API errors #110
1 changed files with 10 additions and 1 deletions
|
|
@ -187,10 +187,15 @@ class Twython(object):
|
||||||
'content': content,
|
'content': content,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# wrap the json loads in a try, and defer an error
|
||||||
|
# why? twitter will return invalid json with an error code in the headers
|
||||||
|
json_error = False
|
||||||
try:
|
try:
|
||||||
content = simplejson.loads(content)
|
content = simplejson.loads(content)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise TwythonError('Response was not valid JSON, unable to decode.')
|
json_error= True
|
||||||
|
content= {}
|
||||||
|
|
||||||
if response.status_code > 304:
|
if response.status_code > 304:
|
||||||
# If there is no error message, use a default.
|
# If there is no error message, use a default.
|
||||||
|
|
@ -207,6 +212,10 @@ class Twython(object):
|
||||||
error_code=response.status_code,
|
error_code=response.status_code,
|
||||||
retry_after=response.headers.get('retry-after'))
|
retry_after=response.headers.get('retry-after'))
|
||||||
|
|
||||||
|
# if we have a json error here , then it's not an official TwitterAPI error
|
||||||
|
if json_error:
|
||||||
|
raise TwythonError('Response was not valid JSON, unable to decode.')
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue