Skip to content

Commit

Permalink
fix(service-worker): throw a critical error when handleFetch fails (a…
Browse files Browse the repository at this point in the history
…ngular#51885)

On Safari, the cache might fail on methods like `match` with an `Internal error`. Critical errors allows to fallback to `safeFetch()` in the `Driver`.

fixes: angular#50378

PR Close angular#51885
  • Loading branch information
JeanMeche authored and ChellappanRajan committed Jan 23, 2024
1 parent d7fec23 commit 1e3112c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/service-worker/worker/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ export abstract class AssetGroup {

// Look for a cached response. If one exists, it can be used to resolve the fetch
// operation.
const cachedResponse = await cache.match(req, this.config.cacheQueryOptions);
let cachedResponse: Response|undefined;
try {
// Safari 16.4/17 is known to sometimes throw an unexpected internal error on cache access
// This try/catch is here as a workaround to prevent a failure of the handleFetch
// as the Driver falls back to safeFetch on critical errors.
// See #50378
cachedResponse = await cache.match(req, this.config.cacheQueryOptions);
} catch (error) {
throw new SwCriticalError(`Cache is throwing while looking for a match: ${error}`);
}

if (cachedResponse !== undefined) {
// A response has already been cached (which presumably matches the hash for this
// resource). Check whether it's safe to serve this resource from cache.
Expand Down

0 comments on commit 1e3112c

Please sign in to comment.