|
@@ -305,64 +305,48 @@ 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 {
|
|
|
- // 执行 requestWillFetch 回调
|
|
|
- for (const t of this.iterateCallbacks("requestWillFetch")) {
|
|
|
- n = await t({
|
|
|
- request: n.clone(),
|
|
|
- event: e
|
|
|
- });
|
|
|
- }
|
|
|
+ for (const t of this.iterateCallbacks('requestWillFetch'))
|
|
|
+ n = await t({ request: n.clone(), event: e });
|
|
|
} catch (t) {
|
|
|
- if (t instanceof Error) {
|
|
|
- console.error("requestWillFetch error:", t);
|
|
|
- throw new s("plugin-error-request-will-fetch", {
|
|
|
- thrownErrorMessage: t.message
|
|
|
- });
|
|
|
- }
|
|
|
+ if (t instanceof Error)
|
|
|
+ throw new s('plugin-error-request-will-fetch', {
|
|
|
+ thrownErrorMessage: t.message
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
const r = n.clone();
|
|
|
-
|
|
|
try {
|
|
|
- // 发起 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;
|
|
|
+ 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;
|
|
|
} catch (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;
|
|
|
+ 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)
|
|
|
+ );
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
async fetchAndCachePut(t) {
|
|
|
const e = await this.fetch(t),
|
|
|
s = e.clone();
|