diff --git a/src/modules/parcel-sync/components/parcel-sync-module.tsx b/src/modules/parcel-sync/components/parcel-sync-module.tsx index 940c8ce..5a49848 100644 --- a/src/modules/parcel-sync/components/parcel-sync-module.tsx +++ b/src/modules/parcel-sync/components/parcel-sync-module.tsx @@ -2617,7 +2617,7 @@ export function ParcelSyncModule() {
Layer GIS:{" "} - + {noGeomScan.remoteGisCount.toLocaleString("ro-RO")} {" "} terenuri diff --git a/src/modules/parcel-sync/services/eterra-client.ts b/src/modules/parcel-sync/services/eterra-client.ts index 1d69b61..2e63682 100644 --- a/src/modules/parcel-sync/services/eterra-client.ts +++ b/src/modules/parcel-sync/services/eterra-client.ts @@ -61,7 +61,7 @@ const LOGIN_URL = `${BASE_URL}/api/authentication`; const DEFAULT_TIMEOUT_MS = 40_000; const DEFAULT_PAGE_SIZE = 2000; -const FALLBACK_PAGE_SIZE = 1000; +const PAGE_SIZE_FALLBACKS = [1000, 500, 200]; const MAX_RETRIES = 2; const SESSION_TTL_MS = 9 * 60 * 1000; const MAX_URL_LENGTH = 1500; @@ -353,18 +353,25 @@ export class EterraClient { let data: EsriQueryResponse; try { data = await this.queryLayer(layer, params, Boolean(options?.geometry)); - } catch { - if (pageSize > FALLBACK_PAGE_SIZE) { - pageSize = FALLBACK_PAGE_SIZE; + } catch (err) { + const cause = err instanceof Error ? err.message : String(err); + // Try next smaller page size + const nextSize = PAGE_SIZE_FALLBACKS.find((s) => s < pageSize); + if (nextSize) { + pageSize = nextSize; + await sleep(500); // small delay before retry with smaller page continue; } - throw new Error(`Failed to fetch layer ${layer.name}`); + throw new Error( + `Failed to fetch layer ${layer.name}: ${cause}`, + ); } const features = data.features ?? []; if (features.length === 0) { - if (total && all.length < total && pageSize > FALLBACK_PAGE_SIZE) { - pageSize = FALLBACK_PAGE_SIZE; + const nextSize = PAGE_SIZE_FALLBACKS.find((s) => s < pageSize); + if (total && all.length < total && nextSize) { + pageSize = nextSize; continue; } break; @@ -375,8 +382,9 @@ export class EterraClient { if (onProgress) onProgress(all.length, total); if (total && all.length >= total) break; if (features.length < pageSize) { - if (total && all.length < total && pageSize > FALLBACK_PAGE_SIZE) { - pageSize = FALLBACK_PAGE_SIZE; + const nextSize = PAGE_SIZE_FALLBACKS.find((s) => s < pageSize); + if (total && all.length < total && nextSize) { + pageSize = nextSize; continue; } break;