fix: robust layer fetch (multi-fallback page sizes, error cause), neutral 505 color

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
This commit is contained in:
AI Assistant
2026-03-07 22:01:17 +02:00
parent b287b4c34b
commit a7c9e8a6cc
2 changed files with 18 additions and 10 deletions
@@ -2617,7 +2617,7 @@ export function ParcelSyncModule() {
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<p className="text-sm"> <p className="text-sm">
Layer GIS:{" "} Layer GIS:{" "}
<span className="text-emerald-600 dark:text-emerald-400 font-semibold"> <span className="font-semibold">
{noGeomScan.remoteGisCount.toLocaleString("ro-RO")} {noGeomScan.remoteGisCount.toLocaleString("ro-RO")}
</span>{" "} </span>{" "}
terenuri terenuri
@@ -61,7 +61,7 @@ const LOGIN_URL = `${BASE_URL}/api/authentication`;
const DEFAULT_TIMEOUT_MS = 40_000; const DEFAULT_TIMEOUT_MS = 40_000;
const DEFAULT_PAGE_SIZE = 2000; const DEFAULT_PAGE_SIZE = 2000;
const FALLBACK_PAGE_SIZE = 1000; const PAGE_SIZE_FALLBACKS = [1000, 500, 200];
const MAX_RETRIES = 2; const MAX_RETRIES = 2;
const SESSION_TTL_MS = 9 * 60 * 1000; const SESSION_TTL_MS = 9 * 60 * 1000;
const MAX_URL_LENGTH = 1500; const MAX_URL_LENGTH = 1500;
@@ -353,18 +353,25 @@ export class EterraClient {
let data: EsriQueryResponse; let data: EsriQueryResponse;
try { try {
data = await this.queryLayer(layer, params, Boolean(options?.geometry)); data = await this.queryLayer(layer, params, Boolean(options?.geometry));
} catch { } catch (err) {
if (pageSize > FALLBACK_PAGE_SIZE) { const cause = err instanceof Error ? err.message : String(err);
pageSize = FALLBACK_PAGE_SIZE; // 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; continue;
} }
throw new Error(`Failed to fetch layer ${layer.name}`); throw new Error(
`Failed to fetch layer ${layer.name}: ${cause}`,
);
} }
const features = data.features ?? []; const features = data.features ?? [];
if (features.length === 0) { if (features.length === 0) {
if (total && all.length < total && pageSize > FALLBACK_PAGE_SIZE) { const nextSize = PAGE_SIZE_FALLBACKS.find((s) => s < pageSize);
pageSize = FALLBACK_PAGE_SIZE; if (total && all.length < total && nextSize) {
pageSize = nextSize;
continue; continue;
} }
break; break;
@@ -375,8 +382,9 @@ export class EterraClient {
if (onProgress) onProgress(all.length, total); if (onProgress) onProgress(all.length, total);
if (total && all.length >= total) break; if (total && all.length >= total) break;
if (features.length < pageSize) { if (features.length < pageSize) {
if (total && all.length < total && pageSize > FALLBACK_PAGE_SIZE) { const nextSize = PAGE_SIZE_FALLBACKS.find((s) => s < pageSize);
pageSize = FALLBACK_PAGE_SIZE; if (total && all.length < total && nextSize) {
pageSize = nextSize;
continue; continue;
} }
break; break;