Skip to content

Commit

Permalink
added field for errors to be able handle bad filter or bad credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
mihalikv committed Apr 8, 2018
1 parent fbab449 commit 529fa84
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions O365/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 529fa84

Please sign in to comment.