API Handling setup

This commit is contained in:
Kenneth Reitz
2011-02-19 16:29:15 -05:00
parent 6bf4351a45
commit 5993dbadfe
+22 -1
View File
@@ -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)