Commits

Anonymous committed d6d7837

Slightly better error diagnostics (GoogleLoginFailed exception gives some detail when stringified)

  • Participants
  • Parent commits 53df6c5

Comments (0)

Files changed (1)

src/mekk/greader/reader_client.py

     """
     Exception raised on login failure and other authorization problems.
     """
-    pass
+    def __init__(self, msg, detail=""):
+        if detail:
+            # Google returns bodies like:
+            #
+            # Error=AccountDisabled
+            # Url=https://www.google.com/accounts/ErrorMsg?Email=a%40gmail.com&service=reader&id=adis&timeStmp=1352706633&secTok=.AG5fkS9UcwdwCcoxK7YRqWRQ_3U22aa6IQ%3D%3D
+            #
+            # where the latter yields textual page like "Sorry, your account has been disabled"
+            m = re.search('^Error=(.*)$', detail, re.M)
+            if m:
+                msg += "(" + m.group(1) + ")"
+
+        super(GoogleLoginFailed, self).__init__(msg)
+        
 class GoogleOperationFailed(Exception):
     """
     Exception raised when Google rejects some operation.
             f = urllib2.urlopen( request )
         except urllib2.HTTPError as e:
             if e.code == 403:
-                raise GoogleLoginFailed("%s (%s)" % (e, e.read().rstrip()))
+                raise GoogleLoginFailed(e.msg, e.read().rstrip())
             else:
                 raise
         result = f.read()
 
         sid = re.search('Auth=(\S*)', result).group(1)
         if not sid:
-            raise GoogleLoginFailed("Internal problem, missing Auth header")
+            raise GoogleLoginFailed("API error, missing Auth header")
         return sid
 
     def _get_token(self):