Skip to content

PHONUM-3795 | Handling HTTP Status Code - 429 #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plivo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ class ValidationError(PlivoRestError):

class ForbiddenError(PlivoRestError):
pass

class TooManyRequestsError(PlivoRestError):
pass
7 changes: 6 additions & 1 deletion plivo/rest/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
Loading