fix(scan): timeout i uploadImage + rätt API_BASE_URL så mock-upload når telefonen (MIKRO 51)
CI / Typecheck, test & build (push) Successful in 1m36s
CI / Typecheck, test & build (push) Successful in 1m36s
This commit is contained in:
@@ -99,12 +99,28 @@ export async function uploadImage(
|
||||
localUri: string,
|
||||
): Promise<void> {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user