From 097bed9f2ec1f69fb95e6fbc3c65818fd508b1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20F=C3=BCrhoff?= <12294151+imagoiq@users.noreply.github.com> Date: Tue, 19 Sep 2023 08:54:17 +0200 Subject: [PATCH] fix(demo): caches match doesn't throw errors (#1956) 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 https://github.com/mdn/content/pull/29202 --- .../src/app/common/dependency-link/dependency-link.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/demo/src/app/common/dependency-link/dependency-link.component.ts b/packages/demo/src/app/common/dependency-link/dependency-link.component.ts index af0ad89ca1..6e2a13c073 100644 --- a/packages/demo/src/app/common/dependency-link/dependency-link.component.ts +++ b/packages/demo/src/app/common/dependency-link/dependency-link.component.ts @@ -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);