Fix
This commit is contained in:
1 parent
b0c87ce97f
commit
e261c26e78
1 file changed
+10
-13
+10
-13
@@ -91,20 +91,17 @@ function cached(req) {
|
|||||||
async function answer(input, event) {
|
async function answer(input, event) {
|
||||||
const req = typeof input === 'string' ? new Request(input) : input;
|
const req = typeof input === 'string' ? new Request(input) : input;
|
||||||
|
|
||||||
try {
|
const hit = await cached(req);
|
||||||
const res = await fromNetwork(req);
|
if (hit) return hit;
|
||||||
if (res && res.ok && res.type === 'basic') {
|
|
||||||
const copy = res.clone();
|
const res = await fromNetwork(req);
|
||||||
const write = cacheFor(req).then((c) => c.put(req, copy));
|
if (res && res.ok && res.type === 'basic') {
|
||||||
if (event) event.waitUntil(write);
|
const copy = res.clone();
|
||||||
else write.catch(() => {});
|
const write = cacheFor(req).then((c) => c.put(req, copy));
|
||||||
}
|
if (event) event.waitUntil(write);
|
||||||
return res;
|
else write.catch(() => {});
|
||||||
} catch (err) {
|
|
||||||
const hit = await cached(req);
|
|
||||||
if (hit) return hit;
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pageRequest(url) {
|
function pageRequest(url) {
|
||||||
|
|||||||
Reference in new issue
Block a user