From 8201f0ccecdd2ec3c535c826f3ffa77cd08bac99 Mon Sep 17 00:00:00 2001 From: kapilp93 Date: Fri, 2 Aug 2024 13:52:09 +0530 Subject: [PATCH] Added TooManyRequestsException to handle 429 response status code --- lib/rest/axios.js | 4 ++++ lib/rest/request.js | 1 + lib/utils/exceptions.js | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rest/axios.js b/lib/rest/axios.js index ce91738b..7f42cdd0 100644 --- a/lib/rest/axios.js +++ b/lib/rest/axios.js @@ -77,6 +77,7 @@ export function Axios(config) { 404: Exceptions.ResourceNotFoundError, 405: Exceptions.InvalidRequestError, 406: Exceptions.NotAcceptableError, + 429: Exceptions.TooManyRequestsError, 500: Exceptions.ServerError, } [response.status] || Error; @@ -105,6 +106,7 @@ export function Axios(config) { 404: Exceptions.ResourceNotFoundError, 405: Exceptions.InvalidRequestError, 406: Exceptions.NotAcceptableError, + 429: Exceptions.TooManyRequestsError, 500: Exceptions.ServerError, } [error.response.status] || Error; if (!_.inRange(error.response.status, 200, 300)) { @@ -258,6 +260,7 @@ export function Axios(config) { 500: Exceptions.ServerError, 409: Exceptions.InvalidRequestError, 422: Exceptions.InvalidRequestError, + 429: Exceptions.TooManyRequestsError, 207: Exceptions.InvalidRequestError, } [response.status] || Error; @@ -295,6 +298,7 @@ export function Axios(config) { 500: Exceptions.ServerError, 409: Exceptions.InvalidRequestError, 422: Exceptions.InvalidRequestError, + 429: Exceptions.TooManyRequestsError, 207: Exceptions.InvalidRequestError, } [error.response.status] || Error; if (!_.inRange(error.response.status, 200, 300)) { diff --git a/lib/rest/request.js b/lib/rest/request.js index 4a908190..9974404f 100644 --- a/lib/rest/request.js +++ b/lib/rest/request.js @@ -194,6 +194,7 @@ export function Request(config) { 401: Exceptions.AuthenticationError, 404: Exceptions.ResourceNotFoundError, 405: Exceptions.InvalidRequestError, + 429: Exceptions.TooManyRequestsError, 500: Exceptions.ServerError, } [response.statusCode] || Error; diff --git a/lib/utils/exceptions.js b/lib/utils/exceptions.js index caa0bcda..8ebfff24 100644 --- a/lib/utils/exceptions.js +++ b/lib/utils/exceptions.js @@ -5,4 +5,5 @@ export class InvalidRequestError extends PlivoRestError { } export class PlivoXMLError extends PlivoRestError { } export class PlivoXMLValidationError extends PlivoRestError { } export class AuthenticationError extends PlivoRestError { } -export class NotAcceptableError extends PlivoRestError { } \ No newline at end of file +export class NotAcceptableError extends PlivoRestError { } +export class TooManyRequestsError extends PlivoRestError { } \ No newline at end of file