diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f6f7c6..1052162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## [4.14.2](https://github.com/plivo/plivo-node/releases/tag/v4.14.2)(2021-02-17) +- Fix duplicate call issue for make call API. + ## [4.14.1](https://github.com/plivo/plivo-node/releases/tag/v4.14.1)(2021-02-09) - Fix Buy Number API & env variables support for TypeScript. diff --git a/lib/rest/axios.js b/lib/rest/axios.js index 0b81ddb..5c3879a 100644 --- a/lib/rest/axios.js +++ b/lib/rest/axios.js @@ -20,6 +20,7 @@ export function Axios(config) { const config = error.config; if (counter < max_time && error.response.status >= 500) { counter++; + config.url = options.urls[counter] + options.authId + '/' + options.action; return new Promise((resolve) => { resolve(axios(config)); }) @@ -85,11 +86,26 @@ export function Axios(config) { return new Promise((resolve, reject) => { if (isVoiceReq) { - retryWrapper(axios, {retryTime: 2}); - let retryAttempt; - for (retryAttempt = 0; retryAttempt < 3; retryAttempt++) { - options.url = apiVoiceUris[retryAttempt] + config.authId + '/' + action; + retryWrapper(axios, {retryTime: 2, urls: apiVoiceUris, authId: config.authId, action: action}); + options.url = apiVoiceUris[0] + config.authId + '/' + action; axios(options).then(response => { + const exceptionClass = { + 400: Exceptions.InvalidRequestError, + 401: Exceptions.AuthenticationError, + 404: Exceptions.ResourceNotFoundError, + 405: Exceptions.InvalidRequestError, + 500: Exceptions.ServerError, + } [response.status] || Error; + + if (!_.inRange(response.status, 200, 300)) { + let body = response.data; + if (typeof body === 'object') { + reject(new exceptionClass(JSON.stringify(body))); + } + else { + reject(new exceptionClass(body)); + } + } resolve({ response: response, body: response.data @@ -98,7 +114,6 @@ export function Axios(config) { .catch(function (error) { reject(error.stack+ "\r\n" + JSON.stringify(error.response.data)); }) - } } else { axios(options).then(response => { diff --git a/package.json b/package.json index 705d749..c4d3189 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plivo", - "version": "4.14.1", + "version": "4.14.2", "description": "A Node.js SDK to make voice calls and send SMS using Plivo and to generate Plivo XML", "homepage": "https://github.com/plivo/plivo-node", "files": [