Skip to content

Commit 41ba14f

Browse files
committed
Set minimum retry-after wait time to 1 second
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.
1 parent a410f8f commit 41ba14f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ciscosparkapi/exceptions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ def __init__(self, response):
145145
super(SparkRateLimitError, self).__init__(response)
146146

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

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

160161
def __init__(self, response):
161162
super(SparkRateLimitWarning, self).__init__()
162-
self.retry_after = abs(int(response.headers.get('Retry-After', 15)))
163+
self.retry_after = max(1, int(response.headers.get('Retry-After', 15)))
163164
"""The `Retry-After` time period (in seconds) provided by Cisco Spark.
164165
165166
Defaults to 15 seconds if the response `Retry-After` header isn't
166-
present in the response headers.
167+
present in the response headers, and defaults to a minimum wait time of
168+
1 second if Spark returns a `Retry-After` header of 0 seconds.
167169
168170
"""
169171

0 commit comments

Comments
 (0)