diff --git a/modules/DsAxios.js b/modules/DsAxios.js index 0a7b6b662ab4bdcf97fa692849b492967af38680..4c5db666313d174a928fd49ed722f40d6755e4c1 100644 --- a/modules/DsAxios.js +++ b/modules/DsAxios.js @@ -78,7 +78,7 @@ export const reponseErrorInterceptor = (errorResponse) => { return Promise.reject(errorResponse); }; -function raiseEvent (this, name, params) { +function raiseEvent (self, name, params) { const parameters = []; for (const key in params) { if (params.hasOwnProperty(key)) { @@ -88,8 +88,8 @@ function raiseEvent (this, name, params) { const parameterString = 'name=' + escape(name) + '&' + 'parameter=' + escape(parameters.join(';')); return this.post(paths.RAISE_EVENT, parameterString); } -function subscribe (this, eventName, params, answerEventName, customTimeout) { - const that = this; +function subscribe (self, eventName, params, answerEventName, customTimeout) { + const that = self; const timeout = typeof customTimeout !== 'undefined' ? customTimeout : timeouts.SUBSCRIPTION; that.defaults.timeout = timeout; answerEventName = answerEventName || eventName + '.answer'; @@ -102,30 +102,30 @@ function subscribe (this, eventName, params, answerEventName, customTimeout) { } }) // raise the event to do stuff - .then(() => that.raiseEvent(eventName, params ? params : {})) - // get the answer event, when it finally happens - .then(() => that.get(paths.GET_EVENT, { - params: { - subscriptionID: subscriptionId, - timeout - } - })) - // finally unsubscribe - .then((requestResponse) => { - that.get(paths.UNSUBSCRIBE, { + .then(() => that.raiseEvent(eventName, params ? params : {})) + // get the answer event, when it finally happens + .then(() => that.get(paths.GET_EVENT, { params: { subscriptionID: subscriptionId, - name: answerEventName + timeout } + })) + // finally unsubscribe + .then((requestResponse) => { + that.get(paths.UNSUBSCRIBE, { + params: { + subscriptionID: subscriptionId, + name: answerEventName + } + }) + .catch(); // no point in handling any error here, it's just unsubscription + that.defaults.timeout = timeouts.DEFAULT; + return requestResponse; // result of operation returned for the code that uses this functon, to process }) - .catch(); // no point in handling any error here, it's just unsubscription - that.defaults.timeout = timeouts.DEFAULT; - return requestResponse; // result of operation returned for the code that uses this functon, to process - }) - .catch((e) => { - that.defaults.timeout = timeouts.DEFAULT; - return Promise.reject(e); - }); + .catch((e) => { + that.defaults.timeout = timeouts.DEFAULT; + return Promise.reject(e); + }); } export function getDsAxios (instanceConfig) {