Fixes #302 simplifies json decoding and handling of errors. Adds tests. #308

Merged
cash merged 2 commits from add_error_tests into master 2014-02-19 10:33:15 -08:00
Showing only changes of commit 1e627f9fb1 - Show all commits

View file

@ -175,7 +175,7 @@ class Twython(EndpointsMixin, object):
try: try:
content = response.json() content = response.json()
except json.JSONDecodeError: except ValueError:
raise TwythonError('Response was not valid JSON. Unable to decode.') raise TwythonError('Response was not valid JSON. Unable to decode.')
return content return content
@ -188,7 +188,7 @@ class Twython(EndpointsMixin, object):
content = response.json() content = response.json()
# {"errors":[{"code":34,"message":"Sorry, that page does not exist"}]} # {"errors":[{"code":34,"message":"Sorry, that page does not exist"}]}
error_message = content['errors'][0]['message'] error_message = content['errors'][0]['message']
except json.JSONDecodeError: except ValueError:
# bad json data from Twitter for an error # bad json data from Twitter for an error
pass pass
except (KeyError, IndexError): except (KeyError, IndexError):