Skip to content

Commit

Permalink
Re-enable parsing of error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshthecoder committed Jan 30, 2010
1 parent 27145f4 commit e70a29c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tweepy/binder.py
Expand Up @@ -156,8 +156,7 @@ def execute(self):
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)
Expand Down
11 changes: 11 additions & 0 deletions tweepy/parsers.py
Expand Up @@ -16,6 +16,14 @@ def parse(self, method, payload):
"""
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):

Expand All @@ -36,6 +44,9 @@ def parse(self, method, payload):
else:
return json

def parse_error(self, payload):
return self.json_lib.loads(payload)['error']


class ModelParser(JSONParser):

Expand Down

0 comments on commit e70a29c

Please sign in to comment.