From: Joshua Date: Sat, 30 Jan 2010 21:41:50 +0000 (-0600) Subject: Re-enable parsing of error messages. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e70a29c787794e808506d5a8de0f4b0fd8a60cea;p=tweepy.git Re-enable parsing of error messages. --- diff --git a/tweepy/binder.py b/tweepy/binder.py index 979b82b..e62e9c5 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -156,8 +156,7 @@ def bind_api(**config): 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) diff --git a/tweepy/parsers.py b/tweepy/parsers.py index de6ce1b..8599501 100644 --- a/tweepy/parsers.py +++ b/tweepy/parsers.py @@ -16,6 +16,14 @@ class Parser(object): """ 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): @@ -36,6 +44,9 @@ class JSONParser(Parser): else: return json + def parse_error(self, payload): + return self.json_lib.loads(payload)['error'] + class ModelParser(JSONParser):