Skip to content

Commit

Permalink
Merge branch 'pr/49'
Browse files Browse the repository at this point in the history
  • Loading branch information
cmlccie committed Nov 21, 2017
2 parents ae19a70 + e430603 commit f339017
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions ciscosparkapi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,29 @@ def __init__(self, response):

# Error message
response_code = response.status_code
response_reason = " " + response.reason if response.reason else ""
description = SPARK_RESPONSE_CODES.get(response_code,
"Unknown Response Code")
detail = response_to_string(response)

super(SparkApiError, self).__init__("Response Code [{}] - {}\n{}"
super(SparkApiError, self).__init__("Response Code [{}]{} - {}\n{}"
"".format(response_code,
response_reason,
description,
detail))


class SparkRateLimitError(SparkApiError):
"""Cisco Spark Rate-Limit exceeded Error."""
pass

def __init__(self, response):
super(SparkRateLimitError, self).__init__(response)

# Extended exception data attributes
self.retry_after = response.headers.get('Retry-After', 200)
"""The `Retry-After` time period (in seconds) provided by Cisco Spark.
Defaults to 200 seconds if the response `Retry-After` header isn't
present in the response headers.
"""
2 changes: 1 addition & 1 deletion ciscosparkapi/restsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def request(self, method, url, erc, **kwargs):
# Wait and retry if automatic rate-limit handling is enabled
if self.wait_on_rate_limit and e.retry_after:
logger.info("Received rate-limit message; "
"waiting {:0.0f} seconds."
"waiting {0} seconds."
"".format(e.retry_after))
time.sleep(e.retry_after)
continue
Expand Down

0 comments on commit f339017

Please sign in to comment.