From e678956f19d47ccea09d81641fca84b5f933b4de Mon Sep 17 00:00:00 2001 From: Ponte Date: Wed, 11 Feb 2026 19:32:10 +0100 Subject: [PATCH] Fix: add API request timeout to avoid stuck storage status --- app.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index 033eada..57f8e1a 100644 --- a/app.js +++ b/app.js @@ -636,9 +636,14 @@ function markLocalDataForImport() { } async function apiRequest(path, options = {}) { + const controller = new AbortController(); + const timeoutMs = options.timeoutMs || 6000; + const timeoutId = setTimeout(() => controller.abort(), timeoutMs); + const requestOptions = { method: options.method || "GET", headers: {}, + signal: controller.signal, }; if (options.body !== undefined) { @@ -646,16 +651,20 @@ async function apiRequest(path, options = {}) { requestOptions.body = JSON.stringify(options.body); } - const response = await fetch(path, requestOptions); - const rawText = await response.text(); - const payload = rawText ? JSON.parse(rawText) : {}; + try { + const response = await fetch(path, requestOptions); + const rawText = await response.text(); + const payload = rawText ? JSON.parse(rawText) : {}; - if (!response.ok) { - const message = payload && payload.message ? payload.message : `HTTP ${response.status}`; - throw new Error(message); + if (!response.ok) { + const message = payload && payload.message ? payload.message : `HTTP ${response.status}`; + throw new Error(message); + } + + return payload; + } finally { + clearTimeout(timeoutId); } - - return payload; } function applyCatalogPayload(payload, preferredBrand, preferredConsole) {