Fixed bugs

This commit is contained in:
Koushik-Ayila 2020-08-03 11:15:12 +05:30
parent e05bd27bff
commit 681457d352
2 changed files with 109 additions and 52 deletions

View file

@ -277,7 +277,7 @@ export class Conference extends PlivoResource {
* @promise {PlivoGenericResponse} return PlivoGenericResponse if success
* @fail {Error} return Error
*/
startRecording(params) {
startRecording(params={}) {
params.isVoiceRequest = 'true';
return super.executeAction(this.id + '/Record/', 'POST', params);
}

View file

@ -36,12 +36,12 @@ export function Request(config) {
let isVoiceReq = false;
if (params) {
if (params.hasOwnProperty('is_call_insights_request')) {
options.url = params.call_insights_base_url + params.call_insights_request_path;
delete params.is_call_insights_request;
delete params.call_insights_base_url;
delete params.call_insights_request_path;
delete options.formData;
options.json = params;
options.url = params.call_insights_base_url + params.call_insights_request_path;
delete params.is_call_insights_request;
delete params.call_insights_base_url;
delete params.call_insights_request_path;
delete options.formData;
options.json = params;
}
else if (params.hasOwnProperty('is_voice_request')){
options.url = apiVoiceUris[0] + config.authId + '/' + action;
@ -69,33 +69,38 @@ export function Request(config) {
reject(error);
return;
}
if (response.statusCode >= 500 && isVoiceReq === true){
options.url = apiVoiceUris[1] + config.authId + '/' + action;
if (method === 'GET' && options.formData !== '') {
let query = '?' + queryString.stringify(params);
options.url += query;
}
request(options,(error, response) => {
if(error){
reject(error);
return;
if(isVoiceReq === true){
if (response.statusCode >= 500){
options.url = apiVoiceUris[1] + config.authId + '/' + action;
if (method === 'GET' && options.formData !== '') {
let query = '?' + queryString.stringify(params);
options.url += query;
}
if(response.statusCode >= 500 && isVoiceReq === true){
options.url = apiVoiceUris[2] + config.authId + '/' + action;
if (method === 'GET' && options.formData !== '') {
let query = '?' + queryString.stringify(params);
options.url += query;
request(options,(error, response) => {
if(error){
reject(error);
return;
}
request(options, (error, response, body) => {
if(error){
reject(error);
return;
if(response.statusCode>=500){
options.url = apiVoiceUris[2] + config.authId + '/' + action;
if (method === 'GET' && options.formData !== '') {
let query = '?' + queryString.stringify(params);
options.url += query;
}
if(response.statusCode >= 500 && isVoiceReq === true){
request(options, (error, response) => {
if(error){
reject(error);
return;
}
const exceptionClass = {
400: Exceptions.InvalidRequestError,
401: Exceptions.AuthenticationError,
404: Exceptions.ResourceNotFoundError,
405: Exceptions.InvalidRequestError,
500: Exceptions.ServerError,
} [response.statusCode] || Error;
if (!_.inRange(response.statusCode, 200, 300)) {
body = body || response.body;
if (typeof body === 'object') {
@ -104,46 +109,97 @@ export function Request(config) {
reject(new exceptionClass(body));
}
}
else {
let body = response.body
// else {
let body = response.body;
let isObj = typeof _body === 'object' && _body !== null && !(_body instanceof Array) && !(_body instanceof Date)
if (isObj) {
_body['statusCode'] = response.statusCode;
}
resolve({
response: response,
body: body
});
}
// }
})
}
else {
const exceptionClass = {
400: Exceptions.InvalidRequestError,
401: Exceptions.AuthenticationError,
404: Exceptions.ResourceNotFoundError,
405: Exceptions.InvalidRequestError,
500: Exceptions.ServerError,
} [response.statusCode] || Error;
if (!_.inRange(response.statusCode, 200, 300)) {
body = body || response.body;
if (typeof body === 'object') {
reject(new exceptionClass(JSON.stringify(body)));
} else {
reject(new exceptionClass(body));
}
}
// else {
let body = response.body;
let isObj = typeof _body === 'object' && _body !== null && !(_body instanceof Array) && !(_body instanceof Date)
if (isObj) {
_body['statusCode'] = response.statusCode;
}
let bodyOfTwoRetry = response.body
resolve({
response: response,
body: bodyOfTwoRetry
body: body
});
})
}
})
}
else {
const exceptionClass = {
400: Exceptions.InvalidRequestError,
401: Exceptions.AuthenticationError,
404: Exceptions.ResourceNotFoundError,
405: Exceptions.InvalidRequestError,
500: Exceptions.ServerError,
} [response.statusCode] || Error;
if (!_.inRange(response.statusCode, 200, 300)) {
body = body || response.body;
if (typeof body === 'object') {
reject(new exceptionClass(JSON.stringify(body)));
} else {
reject(new exceptionClass(body));
}
}
// else {
let body = response.body;
let isObj = typeof _body === 'object' && _body !== null && !(_body instanceof Array) && !(_body instanceof Date)
if (isObj) {
_body['statusCode'] = response.statusCode;
}
let bodyOfOneRetry = response.body
resolve({
response: response,
body: bodyOfOneRetry
body: body
});
});
}
const exceptionClass = {
400: Exceptions.InvalidRequestError,
401: Exceptions.AuthenticationError,
404: Exceptions.ResourceNotFoundError,
405: Exceptions.InvalidRequestError,
500: Exceptions.ServerError,
} [response.statusCode] || Error;
if (!_.inRange(response.statusCode, 200, 300)) {
body = body || response.body;
if (typeof body === 'object') {
reject(new exceptionClass(JSON.stringify(body)));
} else {
reject(new exceptionClass(body));
}
}
else {
const exceptionClass = {
400: Exceptions.InvalidRequestError,
401: Exceptions.AuthenticationError,
404: Exceptions.ResourceNotFoundError,
405: Exceptions.InvalidRequestError,
500: Exceptions.ServerError,
} [response.statusCode] || Error;
if (!_.inRange(response.statusCode, 200, 300)) {
body = body || response.body;
if (typeof body === 'object') {
reject(new exceptionClass(JSON.stringify(body)));
} else {
reject(new exceptionClass(body));
}
}
else {
let body = response.body;
let isObj = typeof _body === 'object' && _body !== null && !(_body instanceof Array) && !(_body instanceof Date)
if (isObj) {
@ -154,6 +210,7 @@ export function Request(config) {
body: body
});
}
}
});
});
};