Keep research search recoverable and isolate browser checks [skip ci]

This commit is contained in:
2026-11-07 15:51:12 +08:00
parent 4478750909
commit d527d059eb
14 changed files with 189 additions and 46 deletions
+17
View File
@@ -0,0 +1,17 @@
// Anonymous server-side transport. Expected HTTP/network failures are values;
// callers can keep the search form usable without falling back to sample data.
export function createPaperTransport(origin, requestUpstream = fetch) {
return async function request(path) {
let response;
try {
response = await requestUpstream(new URL(path, origin.replace(/\/$/, "") + "/"), {
cache: "no-store", signal: AbortSignal.timeout(12000), redirect: "error",
});
} catch (error) {
return { ok: false, status: error?.name === "TimeoutError" || error?.name === "AbortError" ? 504 : 503 };
}
if (!response.ok) return { ok: false, status: response.status };
try { return { ok: true, data: await response.json() }; }
catch { return { ok: false, status: 502 }; }
};
}