mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Better handle invalid returns from the API, and recall if we have no messages in the cache
This commit is contained in:
@@ -108,12 +108,15 @@ class Inbox():
|
||||
if not self.login_cookie:
|
||||
raise NotLoggedIn
|
||||
|
||||
if not hasattr(self, '__inbox_cache'):
|
||||
inbox = json.load(self._opener.open(self.REDDIT_API_INBOX))['data']
|
||||
|
||||
self.__inbox_cache = []
|
||||
for msg in inbox['children']:
|
||||
self.__inbox_cache.append(Message(msg['data']))
|
||||
if not hasattr(self, '__inbox_cache') or not len(self.__inbox_cache):
|
||||
inbox = json.load(self._opener.open(self.REDDIT_API_INBOX))
|
||||
|
||||
if inbox and 'data' in inbox:
|
||||
self.__inbox_cache = []
|
||||
for msg in inbox['data']['children']:
|
||||
self.__inbox_cache.append(Message(msg['data']))
|
||||
else:
|
||||
self.__inbox_cache = []
|
||||
|
||||
return self.__inbox_cache
|
||||
|
||||
|
||||
Reference in New Issue
Block a user