diff --git a/plivo/exceptions.py b/plivo/exceptions.py index b964aed1..f269fc6a 100644 --- a/plivo/exceptions.py +++ b/plivo/exceptions.py @@ -29,3 +29,6 @@ class ValidationError(PlivoRestError): class ForbiddenError(PlivoRestError): pass + +class TooManyRequestsError(PlivoRestError): + pass \ No newline at end of file diff --git a/plivo/rest/client.py b/plivo/rest/client.py index 19c2f24e..a943c3a3 100644 --- a/plivo/rest/client.py +++ b/plivo/rest/client.py @@ -10,7 +10,7 @@ from plivo.base import ResponseObject from plivo.exceptions import (AuthenticationError, InvalidRequestError, PlivoRestError, PlivoServerError, - ResourceNotFoundError, ValidationError, ForbiddenError) + ResourceNotFoundError, ValidationError, ForbiddenError, TooManyRequestsError) from plivo.resources import (Accounts, Addresses, Applications, Calls, Token, Conferences, Endpoints, Identities, Messages, Powerpacks, Media, Lookup, Brand, Campaign, Profile, @@ -202,6 +202,11 @@ def process_response(self, 'Unprocessable Entity: ' '{url}'.format(url=response.url)) + if response.status_code == 429: + raise TooManyRequestsError( + 'Too Many Requests: ' + '"{method}" {url}'.format(method=method,url=response.url)) + if response.status_code == 500: if response_json and 'error' in response_json: raise PlivoServerError(response_json.error)