Keep research search recoverable and isolate browser checks [skip ci]
This commit is contained in:
@@ -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 }; }
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user