Skip to content

Commit 2f56db4

Browse files
committed
MOBILE-2915 core: Fix Uncaught promise error if request fails
1 parent 92d6d09 commit 2f56db4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/classes/site.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ export class CoreSite {
582582
});
583583
}
584584

585-
const promise = this.getFromCache(method, data, preSets, false, originalData).catch(() => {
585+
let promise = this.getFromCache(method, data, preSets, false, originalData).catch(() => {
586586
// Do not pass those options to the core WS factory.
587587
return this.wsProvider.call(method, data, wsPreSets).then((response) => {
588588
if (preSets.saveToCache) {
@@ -688,12 +688,13 @@ export class CoreSite {
688688
});
689689

690690
this.ongoingRequests[cacheId] = promise;
691+
691692
// Clear ongoing request after setting the promise (just in case it's already resolved).
692-
promise.finally(() => {
693-
// Make sure we don't clear the promise of a newer request that ignores the cache.
694-
if (this.ongoingRequests[cacheId] === promise) {
695-
delete this.ongoingRequests[cacheId];
696-
}
693+
promise = promise.finally(() => {
694+
// Make sure we don't clear the promise of a newer request that ignores the cache.
695+
if (this.ongoingRequests[cacheId] === promise) {
696+
delete this.ongoingRequests[cacheId];
697+
}
697698
});
698699

699700
return promise.then((response) => {

0 commit comments

Comments
 (0)