mirror of
https://github.com/donl/plivo-node.git
synced 2026-05-31 22:07:36 -06:00
Merge branch 'master' into mms-powerpack
This commit is contained in:
commit
90aa87ee6c
8 changed files with 276 additions and 56 deletions
|
|
@ -1,8 +1,11 @@
|
|||
# Change Log
|
||||
|
||||
## [4.8.0](https://github.com/plivo/plivo-node/releases/tag/v4.8.0)(2020-08-25)
|
||||
## [4.9.0](https://github.com/plivo/plivo-node/releases/tag/v4.8.0)(2020-08-25)
|
||||
- Powerpack for MMS
|
||||
|
||||
## [4.8.0](https://github.com/plivo/plivo-node/releases/tag/v4.8.0)(2020-07-23)
|
||||
- Add retries to multiple regions for voice requests.
|
||||
|
||||
## [4.7.0](https://github.com/plivo/plivo-node/releases/tag/v4.7.0)(2020-05-28)
|
||||
- Add JWT helper functions.
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ export class PlivoResource {
|
|||
client('POST', action + id + '/', params)
|
||||
.then(response => {
|
||||
extend(that, response.body);
|
||||
if (params.hasOwnProperty('isVoiceRequest')){
|
||||
delete params.isVoiceRequest;
|
||||
}
|
||||
extend(that, params);
|
||||
resolve(that);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ export class Application extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
update(params) {
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.update(params);
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +60,7 @@ export class Application extends PlivoResource {
|
|||
if (typeof params.cascade === 'boolean') {
|
||||
params.cascade = params.cascade.toString();
|
||||
}
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.delete(params);
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +88,22 @@ export class ApplicationInterface extends PlivoResourceInterface {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
get(id) {
|
||||
return super.get(id);
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.get(id, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* list applications
|
||||
* @method
|
||||
* @param {object} params - params to list applications
|
||||
* @param {string} [params.subaccount] - ID of the subaccount if present
|
||||
* @param {integer} [params.limit] - To display no of results per page
|
||||
* @param {integer} [params.offset] - No of value items by which results should be offset
|
||||
*/
|
||||
list(params= {}) {
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.list(params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -122,7 +139,7 @@ export class ApplicationInterface extends PlivoResourceInterface {
|
|||
}
|
||||
|
||||
params.app_name = appName;
|
||||
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.create(params);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ export class Call extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
hangup() {
|
||||
return super.delete();
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.delete(params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +50,7 @@ export class Call extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
transfer(params) {
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.update(params);
|
||||
}
|
||||
/**
|
||||
|
|
@ -69,6 +72,7 @@ export class Call extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
startRecording(params) {
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/Record/', 'POST', params);
|
||||
}
|
||||
/**
|
||||
|
|
@ -79,6 +83,7 @@ export class Call extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
stopRecording(params) {
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/Record/', 'DELETE', params);
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +109,7 @@ export class Call extends PlivoResource {
|
|||
startPlayingMusic(urls, optionalParams) {
|
||||
let params = optionalParams || {};
|
||||
params.urls = urls;
|
||||
params.isVoiceRequest = 'true';
|
||||
|
||||
let errors = validate([
|
||||
{field: 'urls', value: urls, validators: ['isRequired', 'isString']}
|
||||
|
|
@ -122,7 +128,9 @@ export class Call extends PlivoResource {
|
|||
* @fail {Error} returns Error
|
||||
*/
|
||||
stopPlayingMusic() {
|
||||
return super.executeAction(this.id + '/Play/', 'DELETE');
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.executeAction(this.id + '/Play/', 'DELETE', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -154,6 +162,7 @@ export class Call extends PlivoResource {
|
|||
|
||||
let params = optionalParams || {};
|
||||
params.text = text;
|
||||
params.isVoiceRequest = 'true';
|
||||
|
||||
return super.executeAction(this.id + '/Speak/', 'POST', params);
|
||||
}
|
||||
|
|
@ -165,7 +174,9 @@ export class Call extends PlivoResource {
|
|||
* @fail {Error} returns Error
|
||||
*/
|
||||
stopSpeakingText() {
|
||||
return super.executeAction(this.id + '/Speak/', 'DELETE');
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/Speak/', 'DELETE', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -185,7 +196,7 @@ export class Call extends PlivoResource {
|
|||
|
||||
let params = optionalParams || {};
|
||||
params.digits = digits;
|
||||
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/DTMF/', 'POST', params);
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +207,9 @@ export class Call extends PlivoResource {
|
|||
* @fail {Error} returns Error
|
||||
*/
|
||||
cancel() {
|
||||
return super.executeAction('Request/' + this.id + '/', 'DELETE', {}, '');
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction('Request/' + this.id + '/', 'DELETE', params, '');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +246,9 @@ export class CallInterface extends PlivoResourceInterface {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return super.get(id);
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.get(id, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -244,6 +259,7 @@ export class CallInterface extends PlivoResourceInterface {
|
|||
* @fail {Error} returns Error
|
||||
*/
|
||||
list(params) {
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.list(params);
|
||||
}
|
||||
|
||||
|
|
@ -289,6 +305,7 @@ export class CallInterface extends PlivoResourceInterface {
|
|||
params.from = from;
|
||||
params.to = _.isArray(to) ? _.join(to, '<') : to;
|
||||
params.answer_url = answerUrl;
|
||||
params.isVoiceRequest = 'true';
|
||||
|
||||
return super.create(params);
|
||||
}
|
||||
|
|
@ -582,6 +599,7 @@ class LiveCallInterface extends PlivoResourceInterface {
|
|||
}
|
||||
return super.get(id, {
|
||||
status: 'live',
|
||||
isVoiceRequest: 'true'
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -591,7 +609,7 @@ class LiveCallInterface extends PlivoResourceInterface {
|
|||
params = {}
|
||||
}
|
||||
params.status = 'live'
|
||||
|
||||
params.isVoiceRequest = 'true'
|
||||
return new Promise((resolve, reject) => {
|
||||
client('GET', action, params)
|
||||
.then(response => {
|
||||
|
|
@ -640,6 +658,7 @@ class QueuedCallInterface extends PlivoResourceInterface {
|
|||
}
|
||||
return super.get(id, {
|
||||
status: 'queued',
|
||||
isVoiceRequest: 'true'
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -647,7 +666,7 @@ class QueuedCallInterface extends PlivoResourceInterface {
|
|||
let client = this[clientKey];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
client('GET', action, {status: 'queued'})
|
||||
client('GET', action, {status: 'queued', isVoiceRequest: 'true'})
|
||||
.then(response => {
|
||||
let calls = [];
|
||||
response.body.calls.forEach(callUuid => {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ export class Conference extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
hangup() {
|
||||
return super.delete();
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.delete(params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -48,7 +50,9 @@ export class Conference extends PlivoResource {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/', 'DELETE');
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/', 'DELETE', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,8 +70,9 @@ export class Conference extends PlivoResource {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Kick/', 'POST');
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Kick/', 'POST',params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,7 +90,9 @@ export class Conference extends PlivoResource {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Mute/', 'POST');
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Mute/', 'POST',params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -103,8 +110,9 @@ export class Conference extends PlivoResource {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Mute/', 'DELETE');
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Mute/', 'DELETE', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -122,7 +130,9 @@ export class Conference extends PlivoResource {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Deaf/', 'POST');
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Deaf/', 'POST', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,7 +150,9 @@ export class Conference extends PlivoResource {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Deaf/', 'DELETE');
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true'
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Deaf/', 'DELETE', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,6 +173,7 @@ export class Conference extends PlivoResource {
|
|||
return errors;
|
||||
}
|
||||
let params = {url: url};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Play/', 'POST', params);
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +192,9 @@ export class Conference extends PlivoResource {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Play/', 'DELETE');
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Play/', 'DELETE', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -204,7 +219,7 @@ export class Conference extends PlivoResource {
|
|||
}
|
||||
let params = optionalParams || {};
|
||||
params.text = text;
|
||||
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Speak/', 'POST', params);
|
||||
}
|
||||
|
||||
|
|
@ -223,6 +238,8 @@ export class Conference extends PlivoResource {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/Member/' + memberId + '/Speak/', 'DELETE');
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +277,8 @@ 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);
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +289,9 @@ export class Conference extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
stopRecording() {
|
||||
return super.executeAction(this.id + '/Record/', 'DELETE');
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.executeAction(this.id + '/Record/', 'DELETE', params);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +325,9 @@ export class ConferenceInterface extends PlivoResourceInterface {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return super.get(id);
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.get(id, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -316,9 +338,10 @@ export class ConferenceInterface extends PlivoResourceInterface {
|
|||
*/
|
||||
list() {
|
||||
let client = this[clientKey];
|
||||
|
||||
let params = {}
|
||||
params.isVoiceRequest = 'true';
|
||||
return new Promise((resolve, reject) => {
|
||||
client('GET', action)
|
||||
client('GET', action, params)
|
||||
.then(response => {
|
||||
let conferences = [];
|
||||
response.body.conferences.forEach(conference => {
|
||||
|
|
@ -349,9 +372,11 @@ export class ConferenceInterface extends PlivoResourceInterface {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return new Conference(this[clientKey], {
|
||||
id: conferenceName
|
||||
}).delete();
|
||||
}).delete(params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -361,8 +386,10 @@ export class ConferenceInterface extends PlivoResourceInterface {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
hangupAll() {
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return new Conference(this[clientKey])
|
||||
.executeAction('', 'DELETE');
|
||||
.executeAction('', 'DELETE', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ export class Endpoint extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
update(params) {
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.update(params);
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +47,9 @@ export class Endpoint extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
delete() {
|
||||
return super.delete();
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.delete(params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -74,7 +77,15 @@ export class EndpointInterface extends PlivoResourceInterface {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
get(id) {
|
||||
return super.get(id);
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.get(id, params);
|
||||
}
|
||||
|
||||
list() {
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.list(params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +117,7 @@ export class EndpointInterface extends PlivoResourceInterface {
|
|||
if (appId) {
|
||||
params.app_id = appId;
|
||||
}
|
||||
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.create(params);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ export class Recording extends PlivoResource {
|
|||
* @fail {Error} return Error
|
||||
*/
|
||||
delete() {
|
||||
return super.delete();
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.delete(params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -63,7 +65,24 @@ export class RecordingInterface extends PlivoResourceInterface {
|
|||
if (errors) {
|
||||
return errors;
|
||||
}
|
||||
return super.get(id);
|
||||
let params = {};
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.get(id, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* list recordings
|
||||
* @method
|
||||
* @param {object} params - params to list recordings
|
||||
* @param {string} [params.subaccount] - ID of the subaccount if present
|
||||
* @param {string} [params.callUuid] - Call UUID of the call to filter recordings associated with it
|
||||
* @param {string} [params.addTime] - Filter based on the timings they were added
|
||||
* @param {string} [params.limit] - Display no of results per page
|
||||
* @param {string} [params.offset] - No of value items by which results should be offset
|
||||
*/
|
||||
list(params= {}) {
|
||||
params.isVoiceRequest = 'true';
|
||||
return super.list(params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -32,17 +32,23 @@ export function Request(config) {
|
|||
headers: headers,
|
||||
json: true
|
||||
};
|
||||
|
||||
let apiVoiceUris = ['https://voice.plivo.com/v1/Account/','https://voice-usw1.plivo.com/v1/Account/','https://voice-use1.plivo.com/v1/Account/'];
|
||||
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;
|
||||
delete params.is_voice_request;
|
||||
isVoiceReq = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (method === 'GET' && options.formData !== '') {
|
||||
let query = '?' + queryString.stringify(params);
|
||||
|
|
@ -64,22 +70,136 @@ export function Request(config) {
|
|||
return;
|
||||
}
|
||||
|
||||
const exceptionClass = {
|
||||
400: Exceptions.InvalidRequestError,
|
||||
401: Exceptions.AuthenticationError,
|
||||
404: Exceptions.ResourceNotFoundError,
|
||||
405: Exceptions.InvalidRequestError,
|
||||
500: Exceptions.ServerError,
|
||||
} [response.statusCode] || Error;
|
||||
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;
|
||||
}
|
||||
request(options,(error, response) => {
|
||||
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;
|
||||
}
|
||||
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') {
|
||||
reject(new exceptionClass(JSON.stringify(body)));
|
||||
} else {
|
||||
reject(new exceptionClass(body));
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
resolve({
|
||||
response: response,
|
||||
body: body
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
|
|
@ -90,6 +210,7 @@ export function Request(config) {
|
|||
body: body
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue