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">
<p className="text-sm">
Layer GIS:{" "}
<span className="text-emerald-600 dark:text-emerald-400 font-semibold">
<span className="font-semibold">
{noGeomScan.remoteGisCount.toLocaleString("ro-RO")}
</span>{" "}
terenuri
@@ -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;