Sfoglia il codice sorgente

Update workbox-27b29e6f.js

lex-xin 3 mesi fa
parent
commit
3dba9c529c
1 ha cambiato i file con 50 aggiunte e 34 eliminazioni
  1. 50 34
      dist/workbox-27b29e6f.js

+ 50 - 34
dist/workbox-27b29e6f.js

@@ -305,48 +305,64 @@ define(['exports'], function (t) {
     async fetch(t) {
       const { event: e } = this;
       let n = L(t);
-      if (
-        'navigate' === n.mode &&
-        e instanceof FetchEvent &&
-        e.preloadResponse
-      ) {
-        const t = await e.preloadResponse;
-        if (t) return t;
+
+      // 检查预加载响应
+      if ("navigate" === n.mode && e instanceof FetchEvent && e.preloadResponse) {
+          const t = await e.preloadResponse;
+          if (t) return t;
       }
-      const i = this.hasCallback('fetchDidFail') ? n.clone() : null;
+
+      const i = this.hasCallback("fetchDidFail") ? n.clone() : null;
+
       try {
-        for (const t of this.iterateCallbacks('requestWillFetch'))
-          n = await t({ request: n.clone(), event: e });
+          // 执行 requestWillFetch 回调
+          for (const t of this.iterateCallbacks("requestWillFetch")) {
+              n = await t({
+                  request: n.clone(),
+                  event: e
+              });
+          }
       } catch (t) {
-        if (t instanceof Error)
-          throw new s('plugin-error-request-will-fetch', {
-            thrownErrorMessage: t.message
-          });
+          if (t instanceof Error) {
+              console.error("requestWillFetch error:", t);
+              throw new s("plugin-error-request-will-fetch", {
+                  thrownErrorMessage: t.message
+              });
+          }
       }
+
       const r = n.clone();
+
       try {
-        let t;
-        t = await fetch(
-          n,
-          'navigate' === n.mode ? void 0 : this.l.fetchOptions
-        );
-        for (const s of this.iterateCallbacks('fetchDidSucceed'))
-          t = await s({ event: e, request: r, response: t });
-        return t;
+          // 发起 fetch 请求
+          let t = await fetch(n, "navigate" === n.mode ? void 0 : this.l.fetchOptions);
+
+          // 执行 fetchDidSucceed 回调
+          for (const s of this.iterateCallbacks("fetchDidSucceed")) {
+              t = await s({
+                  event: e,
+                  request: r,
+                  response: t
+              });
+          }
+
+          return t;
       } catch (t) {
-        console.error(`Unable to fetch a request.`, t);
-        throw (
-          (i &&
-            (await this.runCallbacks('fetchDidFail', {
-              error: t,
-              event: e,
-              originalRequest: i.clone(),
-              request: r.clone()
-            })),
-          t)
-        );
+          console.error("Fetch failed:", t);
+
+          // 执行 fetchDidFail 回调
+          if (i) {
+              await this.runCallbacks("fetchDidFail", {
+                  error: t,
+                  event: e,
+                  originalRequest: i.clone(),
+                  request: r.clone()
+              });
+          }
+
+          throw t;
       }
-    }
+  }
     async fetchAndCachePut(t) {
       const e = await this.fetch(t),
         s = e.clone();