MOBILE-2911 site: Clone response when reusing cache promise

main
Dani Palou 2019-03-12 09:30:37 +01:00
parent 38e079bd87
commit 5cc5394f8e
1 changed files with 13 additions and 4 deletions

View File

@ -576,7 +576,12 @@ export class CoreSite {
// Check for an ongoing identical request if we're not ignoring cache.
if (preSets.getFromCache && this.ongoingRequests[cacheId]) {
return this.ongoingRequests[cacheId];
return this.ongoingRequests[cacheId].then((response) => {
// Clone the data, this may prevent errors if in the callback the object is modified.
return this.utils.clone(response);
}).catch((error) => {
return Promise.reject(this.utils.clone(error));
});
}
const promise = this.getFromCache(method, data, preSets, false, originalData).catch(() => {
@ -586,8 +591,7 @@ export class CoreSite {
this.saveToCache(method, data, response, preSets);
}
// We pass back a clone of the original object, this may prevent errors if in the callback the object is modified.
return this.utils.clone(response);
return response;
}).catch((error) => {
if (error.errorcode == 'invalidtoken' ||
(error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) {
@ -694,7 +698,12 @@ export class CoreSite {
}
});
return promise;
return promise.then((response) => {
// We pass back a clone of the original object, this may prevent errors if in the callback the object is modified.
return this.utils.clone(response);
}).catch((error) => {
return Promise.reject(this.utils.clone(error));
});
}
/**