self.api.last_response = resp
if resp.status != 200:
try:
- #TODO: parse error message
- raise Exception
+ error_msg = self.api.parser.parse_error(self, resp.read())
except Exception:
error_msg = "Twitter error response: status code = %s" % resp.status
raise TweepError(error_msg)
"""
raise NotImplementedError
+ def parse_error(self, payload):
+ """
+ Parse the error message from payload.
+ If unable to parse the message, throw an exception
+ and default error message will be used.
+ """
+ raise NotImplementedError
+
class JSONParser(Parser):
else:
return json
+ def parse_error(self, payload):
+ return self.json_lib.loads(payload)['error']
+
class ModelParser(JSONParser):