From ea1f9a113ab5b82ffaf1ac6b21dbae251848692c Mon Sep 17 00:00:00 2001 From: "Sven (AAMOS AI)" Date: Fri, 14 Aug 2026 17:49:40 +0700 Subject: [PATCH] =?UTF-8?q?fix(scan):=20timeout=20i=20uploadImage=20+=20r?= =?UTF-8?q?=C3=A4tt=20API=5FBASE=5FURL=20s=C3=A5=20mock-upload=20n=C3=A5r?= =?UTF-8?q?=20telefonen=20(MIKRO=2051)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mobile/src/lib/api.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/mobile/src/lib/api.ts b/apps/mobile/src/lib/api.ts index c13fd97..32a597a 100644 --- a/apps/mobile/src/lib/api.ts +++ b/apps/mobile/src/lib/api.ts @@ -99,12 +99,28 @@ export async function uploadImage( localUri: string, ): Promise { const blob = await (await fetch(localUri)).blob(); - const res = await fetch(upload.uploadUrl, { - method: "PUT", - headers: upload.headers, - body: blob, - }); - if (!res.ok) throw new ApiError(res.status, "UPLOAD_FAILED", "Bilduppladdningen misslyckades."); + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(), 30000); + try { + const res = await fetch(upload.uploadUrl, { + method: "PUT", + headers: upload.headers, + body: blob, + signal: controller.signal, + }); + if (!res.ok) throw new ApiError(res.status, "UPLOAD_FAILED", "Bilduppladdningen misslyckades."); + } catch (err) { + if (err instanceof Error && err.name === "AbortError") { + throw new ApiError( + 0, + "UPLOAD_TIMEOUT", + "Uppladdningen tog för lång tid – kontrollera nätverket och försök igen.", + ); + } + throw err; + } finally { + clearTimeout(timer); + } } export interface ConsentStatus {