Added a timeout for fetch (#965)

Added a timeout for fetch
pull/972/head
Ross 2024-07-22 08:36:02 -07:00 committed by GitHub
parent b1dcbc3454
commit 121ecb328a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 0 deletions

View File

@ -2,6 +2,8 @@ import { SpacePrimitives } from "./space_primitives.ts";
import { FileMeta } from "../../plug-api/types.ts";
import { flushCachesAndUnregisterServiceWorker } from "../sw_util.ts";
const fetchTimeout = 5000;
export class HttpSpacePrimitives implements SpacePrimitives {
constructor(
readonly url: string,
@ -29,6 +31,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
}
try {
options.signal = AbortSignal.timeout(fetchTimeout);
const result = await fetch(url, options);
if (result.status === 503) {
throw new Error("Offline");