Skip to content

Commit

Permalink
Added request limit exceeded exception
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsulpy committed Feb 8, 2016
1 parent 8af9d76 commit 88ce378
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ISStreamer/Streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ def __ship(retry_attempts, wait=0):
self.console_message("ship: beginning message ship!", level=2)
if (retry_attempts <= 0):
if (self.DebugLevel >= 2):
raise Exception("shipping logs failed.. network issue?")
raise Exception("shipping failed.. network issue?")
else:
self.console_message("ship: ISStreamer failed to ship the logs after a number of attempts.", level=0)
self.console_message("ship: ISStreamer failed to ship after a number of attempts.", level=0)
if (self.MissedEvents == None):
self.MissedEvents = open("err_missed_events.txt", 'w+')
if (self.MissedEvents != None):
Expand All @@ -213,14 +213,19 @@ def __ship(retry_attempts, wait=0):
elif (response.status == 402):
self.console_message("AccessKey exceeded limit for month, check account at www.initialstate.com/app")
raise Exception("PAYMENT_REQUIRED")
elif (response.status == 429):
self.console_message("Request limit exceeded")
raise Exception("REQUEST_LIMIT_EXCEEDED")
else:
self.console_message("ship: failed on attempt {atmpt} (StatusCode: {sc}; Reason: {r})".format(sc=response.status, r=response.reason, atmpt=retry_attempts))
raise Exception("ship exception")
except Exception as ex:
if (len(ex.args) > 0 and ex.args[0] == "PAYMENT_REQUIRED"):
raise Exception("Either account is capped or an upgrade is required.")
if (len(ex.args) > 0 and ex.args[0] == "REQUEST_LIMIT_EXCEEDED"):
raise Exception("Request limit has been exceeded, please limit request rate.")

self.console_message("ship: exception shipping logs on attempt {atmpt}.".format(atmpt=retry_attempts))
self.console_message("ship: exception shipping on attempt {atmpt}.".format(atmpt=retry_attempts))
retry_attempts = retry_attempts - 1
__ship(retry_attempts, 1)

Expand Down

0 comments on commit 88ce378

Please sign in to comment.