From a3beb96fcd7fb3397867e72f842cc6784c689a82 Mon Sep 17 00:00:00 2001 From: Ian Weller Date: Sun, 14 Mar 2010 00:56:35 -0600 Subject: [PATCH] Raise exception on API errors --- src/mw/api.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mw/api.py b/src/mw/api.py index 88dee80..0946782 100644 --- a/src/mw/api.py +++ b/src/mw/api.py @@ -44,7 +44,10 @@ class API(object): data = gzipper.read() else: data = response.read() - return json.loads(data) + the_data = json.loads(data) + if 'error' in the_data.keys(): + raise APIError(the_data['error']['info']) + return def limits(self, low, high): if self._high_limits == None: @@ -59,6 +62,15 @@ class API(object): return low +class APIError(Exception): + + def __init__(self, info): + self.info = info + + def __str__(self): + return self.info + + def pagename_to_filename(name): name = name.replace(' ', '_') name = name.replace('/', '!') -- 2.39.5