Skip to content

Commit

Permalink
Set minimum retry-after wait time to 1 second
Browse files Browse the repository at this point in the history
We believe Cisco Spark is returning a `Retry-After` of `0` most probably due to a millisecond rounding issue,  which would mean that the `Retry-After` time should really fall somewhere between `0 < t < 1`.

To account for the expectation that some amount of wait time was expected before the request should be retried, change any `Retry-After` responses of `0` seconds to `1` second to provide a minimum wait time for requests to be retried.
  • Loading branch information
cmlccie committed Mar 6, 2018
1 parent a410f8f commit 41ba14f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ciscosparkapi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ def __init__(self, response):
super(SparkRateLimitError, self).__init__(response)

# Extended exception data attributes
self.retry_after = abs(int(response.headers.get('Retry-After', 15)))
self.retry_after = max(1, int(response.headers.get('Retry-After', 15)))
"""The `Retry-After` time period (in seconds) provided by Cisco Spark.
Defaults to 15 seconds if the response `Retry-After` header isn't
present in the response headers.
present in the response headers, and defaults to a minimum wait time of
1 second if Spark returns a `Retry-After` header of 0 seconds.
"""

Expand All @@ -159,11 +160,12 @@ class SparkRateLimitWarning(UserWarning):

def __init__(self, response):
super(SparkRateLimitWarning, self).__init__()
self.retry_after = abs(int(response.headers.get('Retry-After', 15)))
self.retry_after = max(1, int(response.headers.get('Retry-After', 15)))
"""The `Retry-After` time period (in seconds) provided by Cisco Spark.
Defaults to 15 seconds if the response `Retry-After` header isn't
present in the response headers.
present in the response headers, and defaults to a minimum wait time of
1 second if Spark returns a `Retry-After` header of 0 seconds.
"""

Expand Down

0 comments on commit 41ba14f

Please sign in to comment.