MCPcopy Index your code
hub / github.com/ryanmcgrath/twython / _get_error_message

Method _get_error_message

twython/api.py:219–237  ·  view source on GitHub ↗

Parse and return the first error message

(self, response)

Source from the content-addressed store, hash-verified

217 return content
218
219 def _get_error_message(self, response):
220 """Parse and return the first error message"""
221
222 error_message = 'An error occurred processing your request.'
223 try:
224 content = response.json()
225 # {"errors":[{"code":34,"message":"Sorry,
226 # that page does not exist"}]}
227 error_message = content['errors'][0]['message']
228 except TypeError:
229 error_message = content['errors']
230 except ValueError:
231 # bad json data from Twitter for an error
232 pass
233 except (KeyError, IndexError):
234 # missing data so fallback to default message
235 pass
236
237 return error_message
238
239 def request(self, endpoint, method='GET', params=None, version='1.1', json_encoded=False):
240 """Return dict of response received from Twitter's API

Callers 1

_requestMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected