mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Add some further error checking to the Reddit API module
This commit is contained in:
@@ -7,6 +7,9 @@ import unicodedata
|
|||||||
class NotLoggedIn(Exception):
|
class NotLoggedIn(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class LoginError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class Comment(dict):
|
class Comment(dict):
|
||||||
""" Abstraction for comment data provided by JSON
|
""" Abstraction for comment data provided by JSON
|
||||||
Comments can be identifed by Kind = 1 """
|
Comments can be identifed by Kind = 1 """
|
||||||
@@ -81,11 +84,15 @@ class Inbox():
|
|||||||
|
|
||||||
jsondoc = json.load(self._url_request(url, data))
|
jsondoc = json.load(self._url_request(url, data))
|
||||||
|
|
||||||
self.login_cookie = jsondoc['json']['data']['cookie']
|
if jsondoc and 'json' in jsondoc:
|
||||||
self.modhash = jsondoc['json']['data']['modhash']
|
if 'data' in jsondoc['json']:
|
||||||
|
self.login_cookie = jsondoc['json']['data']['cookie']
|
||||||
|
self.modhash = jsondoc['json']['data']['modhash']
|
||||||
|
if self.login_cookie:
|
||||||
|
return True
|
||||||
|
elif 'errors' in jsondoc['json']:
|
||||||
|
raise LoginError(jsondoc['json']['errors'])
|
||||||
|
|
||||||
if self.login_cookie:
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user