-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2207af2
commit d3a09cb
Showing
1 changed file
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,58 @@ | ||
diff --git a/node_modules/workbox-precaching/PrecacheController.js b/node_modules/workbox-precaching/PrecacheController.js | ||
index e00975e..b67ba2b 100644 | ||
index e00975e..bfee1cb 100644 | ||
--- a/node_modules/workbox-precaching/PrecacheController.js | ||
+++ b/node_modules/workbox-precaching/PrecacheController.js | ||
@@ -164,7 +164,10 @@ class PrecacheController { | ||
@@ -150,6 +150,7 @@ class PrecacheController { | ||
return waitUntil(event, async () => { | ||
const installReportPlugin = new PrecacheInstallReportPlugin(); | ||
this.strategy.plugins.push(installReportPlugin); | ||
+ const failedUrls = [] | ||
// Cache entries one at a time. | ||
// See https://github.com/GoogleChrome/workbox/issues/2528 | ||
for (const [url, cacheKey] of this._urlsToCacheKeys) { | ||
@@ -164,12 +165,44 @@ class PrecacheController { | ||
params: { cacheKey }, | ||
request, | ||
event, | ||
- })); | ||
+ })).catch(err => { | ||
+ console.warn("Whoops! There was a precaching error. This app may be missing important assets.") | ||
+ })) | ||
+ // DHIS2: Catch precaching errors to provide a more thorough | ||
+ // error message | ||
+ .catch(err => { | ||
+ failedUrls.push(url) | ||
+ console.error(err) | ||
+ }); | ||
} | ||
const { updatedURLs, notUpdatedURLs } = installReportPlugin; | ||
if (process.env.NODE_ENV !== 'production') { | ||
printInstallDetails(updatedURLs, notUpdatedURLs); | ||
} | ||
+ // DHIS2: Log failed requests to give clear feedback, and throw | ||
+ // error to abort installation | ||
+ if (failedUrls.length > 0) { | ||
+ const appVersion = process.env.REACT_APP_DHIS2_APP_VERSION | ||
+ const appName = process.env.REACT_APP_DHIS2_APP_NAME | ||
+ const errorMessage = | ||
+ `Some assets were unable to be fetched and cached when ` + | ||
+ `installing ${appName} version ${appVersion}, so the ` + | ||
+ `installation has been aborted.\n\n` + | ||
+ `If another version of the app is installed in the browser, ` + | ||
+ `you will continue to see that version. If not, you will ` + | ||
+ `see version ${appVersion}, but caching and offline ` + | ||
+ `features will be unavailable, and the app may not be ` + | ||
+ `fully functional due to the missing files. You can find ` + | ||
+ `the app version that's currently active at the bottom ` + | ||
+ `of the user profile menu.\n\n` + | ||
+ `[FOR TECHNICAL USERS]: If another version is installed ` + | ||
+ `and you would like to attempt to view version ` + | ||
+ `${appVersion} (knowing the above caveats), you may use ` + | ||
+ `your browser's developer tools to find the service worker ` + | ||
+ `that's currently active for this app and unregister it.\n\n` + | ||
+ `These are the files that were unable to be fetched and cached:\n` + | ||
+ `${failedUrls.reduce((acc, curr) => acc + ` * ${curr}\n`, '')}` | ||
+ throw new Error(errorMessage) | ||
+ } | ||
+ | ||
return { updatedURLs, notUpdatedURLs }; | ||
}); | ||
} |