diff --git a/src/app/api/eterra/no-geom-scan/route.ts b/src/app/api/eterra/no-geom-scan/route.ts index 662edce..f475083 100644 --- a/src/app/api/eterra/no-geom-scan/route.ts +++ b/src/app/api/eterra/no-geom-scan/route.ts @@ -48,9 +48,23 @@ export async function POST(req: Request) { } const client = await EterraClient.create(username, password); - const result = await scanNoGeometryParcels(client, siruta, { + + // Global timeout: 2 minutes max for the entire scan + const scanPromise = scanNoGeometryParcels(client, siruta, { workspacePk: body.workspacePk ?? null, }); + const timeoutPromise = new Promise((_, reject) => + setTimeout( + () => + reject( + new Error( + "Scanare timeout — serverul eTerra răspunde lent. Reîncearcă mai târziu.", + ), + ), + 120_000, + ), + ); + const result = await Promise.race([scanPromise, timeoutPromise]); return NextResponse.json(result); } catch (error) { diff --git a/src/modules/parcel-sync/components/parcel-sync-module.tsx b/src/modules/parcel-sync/components/parcel-sync-module.tsx index c72f6a6..f94c2be 100644 --- a/src/modules/parcel-sync/components/parcel-sync-module.tsx +++ b/src/modules/parcel-sync/components/parcel-sync-module.tsx @@ -742,6 +742,9 @@ export function ParcelSyncModule() { scannedAt: "", }; try { + // 2min timeout — scan is informational, should not block the page + const scanAbort = new AbortController(); + const scanTimer = setTimeout(() => scanAbort.abort(), 120_000); const res = await fetch("/api/eterra/no-geom-scan", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -749,7 +752,9 @@ export function ParcelSyncModule() { siruta: s, workspacePk: workspacePk ?? undefined, }), + signal: scanAbort.signal, }); + clearTimeout(scanTimer); const data = (await res.json()) as Record; if (data.error) { console.warn("[no-geom-scan]", data.error); @@ -783,8 +788,19 @@ export function ParcelSyncModule() { scannedAt: String(data.scannedAt ?? new Date().toISOString()), }); } - } catch { - setNoGeomScan(emptyResult); + } catch (err) { + // Distinguish timeout from other errors for the user + const isTimeout = + err instanceof DOMException && err.name === "AbortError"; + if (isTimeout) { + console.warn( + "[no-geom-scan] Timeout after 2 min — server eTerra lent", + ); + } + setNoGeomScan({ + ...emptyResult, + scannedAt: isTimeout ? "timeout" : "", + }); } setNoGeomScanning(false); }, @@ -2642,8 +2658,37 @@ export function ParcelSyncModule() {
- Se scanează lista de imobile din eTerra… + Se scanează lista de imobile din eTerra… (max 2 min)
+

+ Poți folosi butoanele de mai jos fără să aștepți scanarea. +

+
+ + ); + + // Scan timed out + if (scanDone && noGeomScan.scannedAt === "timeout") + return ( + + +
+ + Scanarea a depășit 2 minute — serverul eTerra e lent. +
+

+ Poți lansa sincronizarea fundal fără rezultate de scanare. + Include no-geom nu va fi disponibil. +

+
);