Skip to content

Commit

Permalink
Better errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryszard committed Jul 7, 2009
1 parent 31a5464 commit 6b3f2f7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions netflix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@

logging.basicConfig(level=logging.DEBUG,)

class NotFound(Exception):
class NetflixError(Exception):
pass

class NotFound(NetflixError):
pass

class AuthError(NetflixError):
pass

class NetflixObject(object):
Expand Down Expand Up @@ -257,5 +263,12 @@ def request(self, url, token=None, **args):
time.sleep(1)
req = urllib2.urlopen(oa_req.to_url())
except urllib2.HTTPError, e:
raise NotFound(url, e.read())
error = e.read()
try:
error = json.loads(error)
if error['status']['status_code'] == "401" and error['status']['message'] == "Access Token Validation Failed":
raise AuthError(url)
except (KeyError, ValueError):
pass
raise NotFound(url, error)
return json.load(req, object_hook=self.object_hook)

0 comments on commit 6b3f2f7

Please sign in to comment.