Fix: add API request timeout to avoid stuck storage status

This commit is contained in:
Ponte
2026-02-11 19:32:10 +01:00
parent 3b86c381e3
commit e678956f19

9
app.js
View File

@@ -636,9 +636,14 @@ function markLocalDataForImport() {
} }
async function apiRequest(path, options = {}) { async function apiRequest(path, options = {}) {
const controller = new AbortController();
const timeoutMs = options.timeoutMs || 6000;
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
const requestOptions = { const requestOptions = {
method: options.method || "GET", method: options.method || "GET",
headers: {}, headers: {},
signal: controller.signal,
}; };
if (options.body !== undefined) { if (options.body !== undefined) {
@@ -646,6 +651,7 @@ async function apiRequest(path, options = {}) {
requestOptions.body = JSON.stringify(options.body); requestOptions.body = JSON.stringify(options.body);
} }
try {
const response = await fetch(path, requestOptions); const response = await fetch(path, requestOptions);
const rawText = await response.text(); const rawText = await response.text();
const payload = rawText ? JSON.parse(rawText) : {}; const payload = rawText ? JSON.parse(rawText) : {};
@@ -656,6 +662,9 @@ async function apiRequest(path, options = {}) {
} }
return payload; return payload;
} finally {
clearTimeout(timeoutId);
}
} }
function applyCatalogPayload(payload, preferredBrand, preferredConsole) { function applyCatalogPayload(payload, preferredBrand, preferredConsole) {