From 03a2efa4f4a3d36103eb29b8bb9799558622b13a Mon Sep 17 00:00:00 2001 From: Koushik-Ayila Date: Wed, 17 Feb 2021 11:33:56 +0530 Subject: [PATCH] Fixed bug on multiple call placing during retries. --- lib/rest/axios.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) 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 => {