Skip to content

Commit

Permalink
fix: add thorough error message
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Aug 2, 2023
1 parent 2207af2 commit d3a09cb
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions patches/workbox-precaching+6.5.3.patch
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 };
});
}

0 comments on commit d3a09cb

Please sign in to comment.