From 529fa84dee1f1f2011bac8b903df15cc414eedbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viliam=20Mih=C3=A1lik?= Date: Sun, 8 Apr 2018 22:52:07 +0200 Subject: [PATCH] added field for errors to be able handle bad filter or bad credentials --- O365/inbox.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/O365/inbox.py b/O365/inbox.py index cef97028d0a74..b50242bf82ec4 100644 --- a/O365/inbox.py +++ b/O365/inbox.py @@ -28,6 +28,7 @@ def __init__(self, auth, getNow=True, verify=True): log.debug('creating inbox for the email %s',auth[0]) self.auth = auth self.messages = [] + self.errors = '' self.filters = '' self.order_by = '' @@ -55,6 +56,13 @@ def getMessages(self, number = 10): log.debug('fetching messages.') response = requests.get(self.inbox_url,auth=self.auth,params={'$orderby':self.order_by, '$filter':self.filters, '$top':number},verify=self.verify) + if response.status_code in [400, 500]: + self.errors = response.text + return False + elif response.status_code in [401]: + self.errors = response.reason + return False + log.info('Response from O365: %s', str(response)) #check that there are messages @@ -83,6 +91,9 @@ def getMessages(self, number = 10): log.debug('all messages retrieved and put in to the list.') return True + def getErrors(self): + return self.errors + def getOrderBy(self): return self.order_by