mirror of
https://github.com/donl/plivo-node.git
synced 2026-06-05 14:22:27 -06:00
Fixed bug on multiple call placing during retries.
This commit is contained in:
parent
cea0a873be
commit
03a2efa4f4
1 changed files with 20 additions and 5 deletions
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue