fix(drone-airspace): refuse empty or incompletely paged FAA snapshots

An upstream answer whose zones all fail validation normalized to an empty
list, and paging that stopped at the page limit while the service still
flagged more records was accepted as complete. Both were cached as a fresh
snapshot for an hour and replaced the last good one. Treat them as failed
refreshes so stale-on-error keeps serving the previous snapshot.
This commit is contained in:
Sameh Khamis committed 2026-11-03 14:33:10 -08:00
1 parent 08b8be26fe
commit 6bdedd8523
3 files changed
+87 -7

No files matched your search

+11 -2
View File
@@ -61,8 +61,12 @@ export function droneAirspaceProxy({
return readResponseJsonCapped(response, cap, signal);
}
// A snapshot is accepted only once the service says it is complete. A page
// limit reached while still flagged, a flagged page that adds nothing, or
// no valid zone at all is a failed refresh, so the last good snapshot stays.
async function fetchZones() {
const features = [];
let complete = false;
for (let page = 0; page < MAX_PAGES; page++) {
const url =
page === 0 ? API_URL : `${API_URL}&resultOffset=${features.length}`;
@@ -70,10 +74,15 @@ export function droneAirspaceProxy({
if (!Array.isArray(payload?.features))
throw new Error('invalid_snapshot');
features.push(...payload.features);
if (!exceededTransferLimit(payload) || !payload.features.length) break;
if (!exceededTransferLimit(payload)) {
complete = true;
break;
}
if (!payload.features.length) break;
}
if (!complete) throw new Error('incomplete_snapshot');
const rows = normalizeDroneAirspaceSnapshot({ features });
if (!rows) throw new Error('invalid_snapshot');
if (!rows?.length) throw new Error('invalid_snapshot');
return { fetchedAt: now(), rows };
}