From 59b1d59574f406eaaf5beadba7b69e80716f7787 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 14 Jul 2023 13:35:30 +0530 Subject: [PATCH] fix: idb is not available in firefox private mode [CW-2217] (#7524) --- .../dashboard/api/CacheEnabledApiClient.js | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/javascript/dashboard/api/CacheEnabledApiClient.js b/app/javascript/dashboard/api/CacheEnabledApiClient.js index 2c00389e5..9af939c00 100644 --- a/app/javascript/dashboard/api/CacheEnabledApiClient.js +++ b/app/javascript/dashboard/api/CacheEnabledApiClient.js @@ -18,6 +18,10 @@ class CacheEnabledApiClient extends ApiClient { return this.getFromCache(); } + return this.getFromNetwork(); + } + + getFromNetwork() { return axios.get(this.url); } @@ -32,7 +36,12 @@ class CacheEnabledApiClient extends ApiClient { } async getFromCache() { - await this.dataManager.initDb(); + try { + // IDB is not supported in Firefox private mode: https://bugzilla.mozilla.org/show_bug.cgi?id=781982 + await this.dataManager.initDb(); + } catch { + return this.getFromNetwork(); + } const { data } = await axios.get( `/api/v1/accounts/${this.accountIdFromRoute}/cache_keys` @@ -55,16 +64,22 @@ class CacheEnabledApiClient extends ApiClient { } async refetchAndCommit(newKey = null) { - await this.dataManager.initDb(); - const response = await axios.get(this.url); - this.dataManager.replace({ - modelName: this.cacheModelName, - data: this.extractDataFromResponse(response), - }); + const response = await this.getFromNetwork(); - await this.dataManager.setCacheKeys({ - [this.cacheModelName]: newKey, - }); + try { + await this.dataManager.initDb(); + + this.dataManager.replace({ + modelName: this.cacheModelName, + data: this.extractDataFromResponse(response), + }); + + await this.dataManager.setCacheKeys({ + [this.cacheModelName]: newKey, + }); + } catch { + // Ignore error + } return response; }