fix(storm-intel): graceful hail proxy error + suppress inflated homes total

Hail Recon fetch now checks Content-Type before parsing JSON — when running
under pnpm dev (Vite only), the proxy JS file is served as-is; the check
catches the non-JSON response and flags it as proxy_unavailable, surfacing
"Not available in dev mode" instead of the raw parse-error string.

Est. Homes header now shows "—" when no events are event-pinned. The
previous totalHomes sum across all 37 NWS warning polygons (each 100–500 sq mi)
produced a nonsensical 19.7M figure. The number is only meaningful per-event
or when the user explicitly pins events to compare.
This commit is contained in:
Satyam-Rastogi
2026-05-19 02:39:19 +05:30
parent 30728a0db6
commit e754911e0b
+13 -5
View File
@@ -1352,7 +1352,13 @@ const StormIntelPage = () => {
const [lat, lng] = pin;
setPinHailData(prev => ({ ...prev, [idx]: { loading: true, data: null, error: null } }));
fetch(`/api/hail-proxy?endpoint=ImpactDatesForLatLong&Lat=${lat}&Long=${lng}&Months=60`)
.then(r => r.json())
.then(async r => {
const ct = r.headers.get('content-type') || '';
if (!ct.includes('json')) throw new Error('proxy_unavailable');
const body = await r.json();
if (!r.ok) throw new Error(body?.error || `HTTP ${r.status}`);
return body;
})
.then(data => setPinHailData(prev => ({ ...prev, [idx]: { loading: false, data, error: null } })))
.catch(err => setPinHailData(prev => ({ ...prev, [idx]: { loading: false, data: null, error: err.message } })));
});
@@ -1469,11 +1475,11 @@ const StormIntelPage = () => {
<p className="text-[10px] font-bold uppercase tracking-wider text-zinc-400">Storms</p>
</div>
<div className="w-px h-8 bg-zinc-200 dark:bg-white/10" />
<div className="text-right" title={pinnedHomes !== null ? 'Sum of est. damaged homes across pinned events — zones may overlap' : 'Est. homes with claimable damage across all visible events'}>
<p className={`text-xl font-black ${pinnedHomes !== null ? 'text-amber-500' : 'text-zinc-900 dark:text-white'}`}>
<div className="text-right" title={pinnedHomes !== null ? 'Sum of est. damaged homes across pinned events — zones may overlap' : 'Pin events to see estimated homes affected'}>
<p className={`text-xl font-black ${pinnedHomes !== null ? 'text-amber-500' : 'text-zinc-400'}`}>
{pinnedHomes !== null
? (pinnedHomes >= 1000 ? `${(pinnedHomes / 1000).toFixed(1)}k` : pinnedHomes.toLocaleString())
: (totalHomes >= 1000 ? `${(totalHomes / 1000).toFixed(1)}k` : totalHomes.toLocaleString())
: '—'
}
</p>
<p className="text-[10px] font-bold uppercase tracking-wider text-zinc-400">
@@ -1829,7 +1835,9 @@ const StormIntelPage = () => {
</span>
);
} else if (entry.error) {
line = <span className="text-[10px] text-red-400">Error: {entry.error}</span>;
line = entry.error === 'proxy_unavailable'
? <span className="text-[10px] text-violet-300/70 italic">Not available in dev mode</span>
: <span className="text-[10px] text-red-400">{entry.error}</span>;
} else {
const parsed = parseHailReconData(entry.data);
if (!parsed) {