Try safeFetch wrapper to handle ENOENT errors if server environment has a filesystem error.

This commit is contained in:
Dillon Kearns 2023-01-09 13:17:22 -08:00
parent e2297cd52f
commit 0f11b031fb

View File

@ -97,7 +97,7 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
} else {
try {
console.time(`fetch ${request.url}`);
const response = await fetch(request.url, {
const response = await safeFetch(fetch, request.url, {
method: request.method,
body: request.body,
headers: {
@ -241,4 +241,17 @@ function jsonResponse(json) {
return { bodyKind: "json", body: json };
}
async function safeFetch(fetch, url, options) {
try {
return await fetch(url, options);
} catch (error) {
console.log("@@@safeFetch error", error);
if ("code" in error && code === "ENOENT") {
return await fetch(url, { cachePath: undefined, ...options });
} else {
throw error;
}
}
}
module.exports = { lookupOrPerform };