From 5993dbadfe71440e2d1e4b6f073be7d329b4da23 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 19 Feb 2011 16:29:15 -0500 Subject: [PATCH] API Handling setup --- convore/api.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/convore/api.py b/convore/api.py index 985f1c0..1a71399 100644 --- a/convore/api.py +++ b/convore/api.py @@ -21,7 +21,26 @@ def get(*path): url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json') r = requests.get(url) - return r + try: + r.raise_for_status() + return r + except requests.HTTPError: + if r.status_code == 401: + raise LoginFailed + else: + raise APIError + + + +# ========== +# Exceptions +# ========== + +class LoginFailed(RuntimeError): + """Login falied!""" + +class APIError(RuntimeError): + """There was a problem properly accessing the Convore API.""" @@ -162,3 +181,5 @@ class Groups(UserList): group.import_from_api(_group) group.joined = True self.data.append(group) + +