From a7c9e8a6cc2ce58f3249d47ce6772f5d3c50f9c2 Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Sat, 7 Mar 2026 22:01:17 +0200 Subject: [PATCH] fix: robust layer fetch (multi-fallback page sizes, error cause), neutral 505 color MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LAYER FETCH: - fetchAllLayerByWhere now falls back through 2000 → 1000 → 500 → 200 instead of just 2000 → 1000 before giving up - 500ms delay between fallback attempts to let eTerra recover - Error message now includes the original cause: 'Failed to fetch layer TERENURI_ACTIVE: Session expired (401)' instead of just 'Failed to fetch layer TERENURI_ACTIVE' DISPLAY: - 505 terenuri count no longer green (was emerald-600, now neutral semibold) It's just a data value, not a status indicator --- .../components/parcel-sync-module.tsx | 2 +- .../parcel-sync/services/eterra-client.ts | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) 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;