Skip to content

Commit f339017

Browse files
committed
Merge branch 'pr/49'
2 parents ae19a70 + e430603 commit f339017

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

ciscosparkapi/exceptions.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,29 @@ def __init__(self, response):
128128

129129
# Error message
130130
response_code = response.status_code
131+
response_reason = " " + response.reason if response.reason else ""
131132
description = SPARK_RESPONSE_CODES.get(response_code,
132133
"Unknown Response Code")
133134
detail = response_to_string(response)
134135

135-
super(SparkApiError, self).__init__("Response Code [{}] - {}\n{}"
136+
super(SparkApiError, self).__init__("Response Code [{}]{} - {}\n{}"
136137
"".format(response_code,
138+
response_reason,
137139
description,
138140
detail))
139141

140142

141143
class SparkRateLimitError(SparkApiError):
142144
"""Cisco Spark Rate-Limit exceeded Error."""
143-
pass
145+
146+
def __init__(self, response):
147+
super(SparkRateLimitError, self).__init__(response)
148+
149+
# Extended exception data attributes
150+
self.retry_after = response.headers.get('Retry-After', 200)
151+
"""The `Retry-After` time period (in seconds) provided by Cisco Spark.
152+
153+
Defaults to 200 seconds if the response `Retry-After` header isn't
154+
present in the response headers.
155+
156+
"""

ciscosparkapi/restsession.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def request(self, method, url, erc, **kwargs):
281281
# Wait and retry if automatic rate-limit handling is enabled
282282
if self.wait_on_rate_limit and e.retry_after:
283283
logger.info("Received rate-limit message; "
284-
"waiting {:0.0f} seconds."
284+
"waiting {0} seconds."
285285
"".format(e.retry_after))
286286
time.sleep(e.retry_after)
287287
continue

0 commit comments

Comments
 (0)