From 17009455daa5a2d71b5667bbf75136ddad4408e0 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 2 Jul 2023 00:16:01 -0700 Subject: [PATCH] fix: :bug: patron timeout --- packages/backend/src/server/api/endpoints/patrons.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/backend/src/server/api/endpoints/patrons.ts b/packages/backend/src/server/api/endpoints/patrons.ts index ac914daa12..353cba1dc0 100644 --- a/packages/backend/src/server/api/endpoints/patrons.ts +++ b/packages/backend/src/server/api/endpoints/patrons.ts @@ -23,8 +23,15 @@ export default define(meta, paramDef, async (ps) => { if (!ps.forceUpdate && cachedPatrons) { patrons = JSON.parse(cachedPatrons); } else { + AbortSignal.timeout ??= function timeout(ms) { + const ctrl = new AbortController() + setTimeout(() => ctrl.abort(), ms) + return ctrl.signal + } + patrons = await fetch( "https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json", + { signal: AbortSignal.timeout(2000) } ) .then((response) => response.json()) .catch(() => {