Skip to content

Commit

Permalink
fix(demo): caches match doesn't throw errors (#1956)
Browse files Browse the repository at this point in the history
I used this snippet to work, but the catch is never called and it
doesn't work when the cache is empty:
https://developer.mozilla.org/en-US/docs/Web/API/Cache/put#examples

A more appropriate snippet is this one:
https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage/match


mdn/content#29202
  • Loading branch information
imagoiq authored Sep 19, 2023
1 parent 01b3d8d commit 097bed9
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class DependencyLinkComponent implements OnDestroy {

const cachedResponse = caches
.match(url)
.catch(() => fetch(url))
.then(response => (response !== undefined ? response : fetch(url)))
.then(response => {
caches.open('npm').then(cache => {
void cache.put(url, response);
Expand Down

0 comments on commit 097bed9

Please sign in to comment.